This page is still under construction.

Parts of this page are still being built. What you see may change.

Social Distancing

Time limit1sMemory limit512 MB

Summary
Place N cows on distinct integer grass points across M disjoint intervals on a line so that the minimum pairwise distance D is as large as possible, and output the largest achievable D.
Level

Hard8 of 10

Topics
Binary search, Greedy, Intervals, Sorting
Solved
No attempts yet

Problem

Farmer John is worried for the health of his cows after an outbreak of the highly contagious bovine disease COWVID-19.

In order to limit transmission of the disease, Farmer John's NN cows (2≤N≤1052 \leq N \leq 10^5) have decided to practice "social distancing" and spread themselves out across the farm. The farm is shaped like a 1D number line, with MM mutually-disjoint intervals (1≤M≤1051 \leq M \leq 10^5) in which there is grass for grazing. The cows want to locate themselves at distinct integer points, each covered in grass, so as to maximize the value of DD, where DD represents the distance between the closest pair of cows. Please help the cows determine the largest possible value of DD.

Input

The first line of input contains NN and MM. The next MM lines each describe an interval in terms of two integers aa and bb, where 0≤a≤b≤10180 \leq a \leq b \leq 10^{18}. No two intervals overlap or touch at their endpoints. A cow standing on the endpoint of an interval counts as standing on grass.

Output

Print the largest possible value of DD such that all pairs of cows are DD units apart. A solution with D>0D>0 is guaranteed to exist.

Hint

One way to achieve D=2D=2 is to have cows at positions 00, 22, 44, 66 and 99.

Examples1

  1. Example 1

    Input
    5 3
    0 2
    4 7
    9 9
    
    Expected output
    2