B. Which floor?

Codeforces
IDCF858B
Time1000ms
Memory256MB
Difficulty
brute forceimplementation
In a building where Polycarp lives there are _equal_ number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are on the second and so on. Polycarp don't remember the total number of flats in the building, so you can consider the building to be infinitely high (i.e. there are infinitely many floors). Note that the floors are numbered from 1. Polycarp remembers on which floors several flats are located. It is guaranteed that this information is not self-contradictory. It means that there exists a building with equal number of flats on each floor so that the flats from Polycarp's memory have the floors Polycarp remembers. Given this information, is it possible to restore the exact floor for flat _n_? ## Input The first line contains two integers _n_ and _m_ (1 ≤ _n_ ≤ 100, 0 ≤ _m_ ≤ 100), where _n_ is the number of the flat you need to restore floor for, and _m_ is the number of flats in Polycarp's memory. _m_ lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers _k__i_, _f__i_ (1 ≤ _k__i_ ≤ 100, 1 ≤ _f__i_ ≤ 100), which means that the flat _k__i_ is on the _f__i_\-th floor. All values _k__i_ are distinct. It is guaranteed that the given information is not self-contradictory. ## Output Print the number of the floor in which the _n_\-th flat is located, if it is possible to determine it in a unique way. Print _\-1_ if it is not possible to uniquely restore this floor. [samples] ## Note In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor. In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-th flat.
Samples
Input #1
10 3
6 2
2 1
7 3
Output #1
4
Input #2
8 4
3 1
6 2
5 2
2 1
Output #2
\-1
API Response (JSON)
{
  "problem": {
    "name": "B. Which floor?",
    "description": {
      "content": "In a building where Polycarp lives there are _equal_ number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbere",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF858B"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "In a building where Polycarp lives there are _equal_ number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbere...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments