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.


-----Examples-----
Input
10 3
6 2
2 1
7 3

Output
4

Input
8 4
3 1
6 2
5 2
2 1

Output
-1



-----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.

Difficulty: MEDIUM

Starter code:

Solutions:
(n, m) = map(int, input().split())
a = []
for i in range(m):
	(k, f) = map(int, input().split())
	a.append((k, f))
fl = []
ps = 0
val = -1
for i in range(1, 1000):
	flag = 1
	for j in range(m):
		if (a[j][0] - 1) // i != a[j][1] - 1:
			flag = 0
	if flag:
		ps += 1
		fl.append(i)
ans = []
for i in range(len(fl)):
	ans.append((n - 1) // fl[i] + 1)
if not len(ans):
	print(-1)
else:
	tmp = ans[0]
	flag = 1
	for i in range(len(ans)):
		if ans[i] != tmp:
			flag = 0
	if not flag:
		print(-1)
	else:
		print(ans[0])


(n, m) = map(int, input().split())
s = []
otv = set()
for i in range(m):
	(z, j) = map(int, input().split())
	s.append((z, j))
for i in range(1, 101):
	o = 1
	for (z, j) in s:
		if (z + i - 1) // i != j:
			o = 0
			break
	if o:
		otv.add((n + i - 1) // i)
if len(otv) == 1:
	print(otv.pop())
else:
	print(-1)


import sys
(n, _, *data) = list(map(int, sys.stdin.read().split()))
fsizes = list(range(1, 102))
for (ki, fi) in zip(data[::2], data[1::2]):
	fsizes = [fs for fs in fsizes if (ki - 1) // fs + 1 == fi]
floors = list({(n - 1) // fs + 1 for fs in fsizes})
print(floors[0] if len(floors) == 1 else -1)


p = lambda : map(int, input().split())
(n, m) = p()
(a, b) = (1, n)
for i in range(m):
	(k, f) = p()
	a = max(1 + (k - 1) // f, a)
	if f > 1:
		b = min((k - 1) // (f - 1), b)
(x, y) = ((n - 1) // a, (n - 1) // b)
print(-1 if x - y else 1 + x)


(n, m) = map(int, input().split(' '))
n -= 1
if m == 0:
	if n == 0:
		print(1)
	else:
		print(-1)
	exit(0)
minAps = 0
maxAps = 100000
for i in range(m):
	(k, f) = map(int, input().split(' '))
	k -= 1
	f -= 1
	if f == 0:
		minAps = max(minAps, k + 1)
	else:
		minAps = max(minAps, 1 + k // (f + 1))
		maxAps = min(maxAps, k // f)
minFloor = n // maxAps
maxFloor = n // minAps
if minFloor == maxFloor:
	print(minFloor + 1)
else:
	print(-1)


(n, m) = map(int, input().split())
k = []
f = []
for _ in range(m):
	(a, b) = map(int, input().split())
	k.append(a)
	f.append(b)
mb = {i for i in range(1, 105)}
for i in range(m):
	now = set()
	for p in range(1, 105):
		if (k[i] - 1) // p + 1 == f[i]:
			now.add(p)
	mb.intersection_update(now)
can = set()
for x in mb:
	can.add((n - 1) // x + 1)
if len(can) != 1:
	print(-1)
else:
	for x in can:
		print(x)


import sys
(n, k) = map(int, input().split())
fl = -1
flats = [-1] * 101
for i in range(k):
	(flat, floor) = map(int, input().split())
	flats[flat] = floor
ans = -1
if flats[n] != -1:
	print(flats[n])
	sys.exit(0)
for i in range(1, 101):
	for j in range(1, 101):
		if flats[j] != -1 and (j - 1) // i + 1 != flats[j]:
			break
	else:
		if ans != -1 and (n - 1) // i + 1 != ans:
			print(-1)
			sys.exit(0)
		else:
			ans = (n - 1) // i + 1
print(ans)


from math import ceil
(n, m) = map(int, input().split())
k = [0] * m
f = [0] * m
p = []
for i in range(m):
	(k[i], f[i]) = map(int, input().split())
for i in range(1, 101):
	good = True
	for j in range(m):
		if f[j] == ceil(k[j] / i):
			continue
		else:
			good = False
			break
	if good:
		p.append(i)
s = set()
for i in p:
	s.add(ceil(n / i))
if len(s) != 1:
	print(-1)
else:
	for i in s:
		print(i)


(n, m) = map(int, input().split())
d = []
count_of_good = 0
good_on_level = []
for i in range(m):
	(a, b) = map(int, input().split())
	d.append((a, b))
for on_level in range(1, 101):
	good = True
	for el in d:
		etaj = el[1]
		kv = el[0]
		if not (etaj - 1) * on_level < kv <= etaj * on_level:
			good = False
			break
	if good:
		count_of_good += 1
		good_on_level.append(on_level)
ans = []
for i in good_on_level:
	if n % i == 0:
		ans.append(n // i)
	else:
		ans.append(n // i + 1)
if len(ans) == 1:
	print(ans[0])
	exit()
for i in range(1, len(ans)):
	if ans[i - 1] != ans[i]:
		print('-1')
		exit()
print(ans[0])


from math import ceil
ans = -1
(n, m) = map(int, input().split())
v = []
for i in range(m):
	(x, y) = map(int, input().split())
	v.append([x, y])
for cf in range(1, 101):
	for elem in v:
		if ceil(elem[0] / cf) != elem[1]:
			break
	else:
		if ans != -1 and ceil(n / cf) != ans:
			print(-1)
			break
		else:
			ans = ceil(n / cf)
else:
	print(ans)


(n, m) = map(int, input().split())
kv = [None] * 101
boo = [False] * 101
for i in range(m):
	(k, j) = map(int, input().split())
	kv[k] = j
for j in range(1, 101):
	qw = True
	for i in range(len(kv)):
		if kv[i] is not None:
			a = (i - 1) // j + 1
			if kv[i] != a:
				qw = False
	boo[j] = qw
a = sum(boo)
first = 0
q = set()
for i in range(len(boo)):
	if boo[i]:
		q.add((n - 1) // i + 1)
if len(q) == 1:
	print(q.pop())
else:
	print(-1)


import math
(n, m) = map(int, input().split())
ls = []
pos = []
for i in range(m):
	(u, v) = map(int, input().split())
	ls.append((u, v))
for i in range(1, 101):
	cnt = 0
	for j in range(m):
		if math.ceil(ls[j][0] / i) == ls[j][1]:
			cnt += 1
		else:
			break
	if cnt == m:
		pos.append(math.ceil(n / i))
print(pos[0] if len(list(set(pos))) == 1 else -1)


(n, m) = map(int, input().split())
a = []
for i in range(m):
	(k, f) = map(int, input().split())
	a.append([k, f])
ans = -1
for i in range(1, 101):
	flag = 0
	for j in range(m):
		k = a[j][0]
		f = a[j][1]
		if k % i == 0:
			if k // i != f:
				flag = 1
				break
		elif k // i + 1 != f:
			flag = 1
			break
	if flag == 0:
		if n % i == 0:
			ans1 = n // i
		else:
			ans1 = n // i + 1
		if ans != -1 and ans != ans1:
			ans = -1
			break
		elif n % i == 0:
			ans = n // i
		else:
			ans = n // i + 1
print(ans)


(n, m) = map(int, input().split())
ans = set()
d = {}
for i in range(m):
	(k, f) = map(int, input().split())
	d[k] = f
for i in range(1, 101):
	floor = 1
	cur_floor = 0
	ans_floor = 0
	for j in range(1, 101):
		if cur_floor == i:
			floor += 1
			cur_floor = 0
		if d.get(j, floor) != floor:
			break
		if j == n:
			ans_floor = floor
		cur_floor += 1
	else:
		ans.add(ans_floor)
if len(ans) > 1 or len(ans) == 0:
	print(-1)
else:
	print(*ans)


(a, b) = list(map(int, input().split()))
mini = 1
maxi = 10000
for i in range(b):
	(x, y) = list(map(int, input().split()))
	if y == 1:
		mini = max(mini, x)
	else:
		mx = (x - 1) // (y - 1)
		mn = (x - 1) // y + 1
		if mn * y >= x:
			mini = max(mini, mn)
		else:
			mini = max(mini, mn + 1)
		if mx * y >= x:
			maxi = min(maxi, mx)
if (a - 1) // maxi == (a - 1) // mini:
	print((a - 1) // maxi + 1)
else:
	print(-1)


(n, m) = map(int, input().split())
memory = []
for i in range(m):
	(a, b) = map(int, input().split())
	memory.append((a, b))
ans = -1
gl_flag = 1
for flat in range(1, 101):
	flag = 1
	for i in range(m):
		if not (memory[i][0] <= memory[i][1] * flat and memory[i][0] > (memory[i][1] - 1) * flat):
			flag = 0
			break
	if flag == 1:
		ans1 = (n - 1) // flat + 1
		if ans != -1 and ans1 != ans:
			gl_flag = 0
			break
		else:
			ans = ans1
if gl_flag == 0:
	print(-1)
else:
	print(ans)


(n, m) = [int(i) for i in input().split()]
a = []
for i in range(m):
	(k, l) = [int(i) for i in input().split()]
	a.append([k, l])
b = set()
for x in range(1, 105):
	for i in range(len(a)):
		q = (a[i][1] - 1) * x + 1
		e = a[i][1] * x
		if a[i][0] < q or a[i][0] > e:
			break
	else:
		b.add((n + x - 1) // x)
if len(b) > 1:
	print(-1)
else:
	print(*b)


def floo(num, k):
	return (num - 1) // k + 1

def main():
	(n, m) = map(int, input().split())
	low = 1
	high = 10 ** 9
	if m == 0:
		if n == 1:
			print(1)
		else:
			print(-1)
		return
	for i in range(m):
		(k, f) = map(int, input().split())
		low = max(low, (k + f - 1) // f)
		if f > 1:
			high = min(high, (k - 1) // (f - 1))
	if floo(n, low) == floo(n, high):
		print(floo(n, low))
	else:
		print(-1)
main()


import os
import sys
import math
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, m) = map(int, input().split())
l = set()
s = {i for i in range(1, 101)}
b = False
for i in range(m):
	(k, f) = map(int, input().split())
	if k == n:
		print(f)
		b = True
		break
	j = 1
	if f == 1:
		l = {i for i in range(k, 101)}
	else:
		while j <= (k - j) // (f - 1):
			if (k - j) % (f - 1) == 0:
				l.add((k - j) // (f - 1))
				j += f - 1
			else:
				j += 1
	s &= l
	l.clear()
a = -1
if b == False:
	t = True
	for j in s:
		if a == -1:
			a = (n - 1) // j
		elif (n - 1) // j != a:
			print(-1)
			t = False
			break
	if t == True:
		print(a + 1)


import sys, os
(n, m) = map(int, input().split())
mi = []
ma = []
if m == 0:
	if n == 1:
		print(1)
	else:
		print(-1)
	exit(0)
	sys.exit()
	os.abort()
for i in range(m):
	(a, b) = map(int, input().split())
	if b == 1:
		ma.append(1000000000)
		mi.append(a)
		if n <= a:
			print(1)
			exit(0)
			sys.exit()
			os.abort()
	else:
		mak = (a - 1) // (b - 1)
		ma.append(mak)
		if a % b == 0:
			mi.append(a // b)
		else:
			mi.append(a // b + 1)
mik = min(ma)
mak = max(mi)
if n % mik == 0:
	a = n // mik
else:
	a = n // mik + 1
if n % mak == 0:
	b = n // mak
else:
	b = n // mak + 1
if a == b:
	print(b)
else:
	print(-1)


import math
(n, m) = map(int, input().split())
flatlist = [0] * m
floorlist = [0] * m
for i in range(m):
	(flatlist[i], floorlist[i]) = map(int, input().split())
k = 0
a = []
for cf in range(1, 101):
	for i in range(m):
		if math.ceil(flatlist[i] / cf) == floorlist[i]:
			k += 1
		else:
			k = 0
	if k == m:
		a.append(cf)
	k = 0
l = 1
if len(a) > 1:
	ans = math.ceil(n / a[0])
	for i in range(1, len(a)):
		if math.ceil(n / a[i]) != ans:
			print(-1)
			l = 0
			break
	if l:
		print(ans)
else:
	print(math.ceil(n / a[0]))


import math

def process(A, n):
	if A == []:
		if n == 1:
			return 1
		return -1
	M_min = 0
	M_max = float('inf')
	for (k, f) in A:
		this_min = k / f
		M_min = max(this_min, M_min)
		if f > 1:
			this_max = (k - 1) / (f - 1)
			M_max = min(this_max, M_max)
	M_min = math.ceil(M_min)
	a1 = (n - 1) // M_min
	if M_max < float('inf'):
		M_max = math.floor(M_max)
		a2 = (n - 1) // M_max
	else:
		a2 = 0
	if a1 == a2:
		return a1 + 1
	else:
		return -1
(n, m) = [int(x) for x in input().split()]
A = []
for i in range(m):
	(k, f) = [int(x) for x in input().split()]
	A.append([k, f])
print(process(A, n))


def check(k):
	global d
	c = 0
	for i in d:
		if i[0] // k != i[1]:
			c = 1
			break
	if c == 0:
		return True
	else:
		return False
(n, m) = map(int, input().split())
d = []
if n == 1:
	print(1)
	exit(0)
for i in range(m):
	(a, b) = map(int, input().split())
	d.append([a - 1, b - 1])
f = 0
a1 = -1
for i in range(1, 101):
	if check(i):
		a = (n - 1) // i
		if a != a1:
			f += 1
		a1 = a
if f != 1:
	print(-1)
else:
	print(a + 1)


(n, m) = list(map(int, input().split()))
l = []
may = []
for i in range(m):
	l.append(list(map(int, input().split())))
g = 0
for i in range(1, 101):
	fl = True
	for j in l:
		a = j[0]
		b = j[1]
		if (a - 1) // i + 1 != b:
			fl = False
			break
	if fl:
		may.append(i)
for i in range(len(may) - 1):
	if (n - 1) // may[i] + 1 != (n - 1) // may[i + 1] + 1:
		print(-1)
		exit()
print((n - 1) // may[0] + 1)


def rec(i):
	nonlocal a
	return i
import sys
from collections import Counter
sys.setrecursionlimit(10 ** 6)
(n, m) = list(map(int, input().split()))
a = [[] for i in range(100)]
b = [i for i in range(1, 101)]
for i in range(m):
	(x, y) = list(map(int, input().split()))
	z = b.copy()
	for i0 in z:
		if not (x - 1 >= (y - 1) * i0 and x - 1 < y * i0):
			b.remove(i0)
a = set()
for i0 in b:
	a.add((n - 1) // i0)
if len(a) == 1:
	print(a.pop() + 1)
else:
	print(-1)


import math
from sys import stdin
from math import ceil
numbers = list(map(int, input().split()))
n = numbers[0]
m = numbers[1]
floors = []
for i in range(m):
	floors.append(tuple(map(int, input().split())))
rez = set()
for i in range(1, 100 + 1):
	ok = True
	for (ki, fi) in floors:
		if (ki + i - 1) // i != fi:
			ok = False
			break
	if ok:
		rez.add((n + i - 1) // i)
if len(rez) == 1:
	x = rez.pop()
	print(x)
else:
	print('-1')


(n, m) = list(map(int, input().split()))
flat = sorted({tuple(map(int, input().split())) for _ in range(m)})
o = []
for i in range(1, 101):
	subset = []
	pos = 0
	f = 1
	for k in range(1, 101):
		pos += 1
		if pos > i:
			pos = 1
			f += 1
		subset.append((k, f))
	if set(flat).issubset(set(subset)):
		o.append(subset[n - 1][1])
if o != [] and len(o) == o.count(o[0]):
	print(o[0])
else:
	print(-1)


(n, m1) = map(int, input().split())
ans = set()
a = []
l = 0
for i in range(m1):
	(k, f) = map(int, input().split())
	a.append((k, f))
for kol in range(1, 101):
	fl = True
	for elem in a:
		k = elem[0]
		f = elem[1]
		if (k + kol - 1) // kol != f:
			fl = False
			break
	if fl:
		ans.add((n + kol - 1) // kol)
if len(ans) != 1:
	print(-1)
	exit()
print(ans.pop())


from math import ceil
(n, m) = tuple(map(int, input().split()))
kf = [tuple(map(int, input().split())) for i in range(m)]
x = 1
y = -1
for i in range(m):
	if x == y:
		break
	(k, f) = kf[i]
	x = max(x, ceil(k / f))
	if f > 1:
		p = int((k - 1) / (f - 1))
		if y == -1 or p < y:
			y = p
if n <= x:
	print(1)
elif ceil(n / x) == ceil(n / y):
	print(ceil(n / x))
else:
	print(-1)


from math import ceil
(n, m) = map(int, input().split())
k = [0 for i in range(m)]
f = [0 for i in range(m)]
x = -1
for i in range(m):
	(k[i], f[i]) = map(int, input().split())
i = 0
while i < m:
	j = i
	while j < m:
		if abs(k[i] - k[j]) == 1 and abs(f[i] - f[j]) == 1:
			if f[i] < f[j]:
				x = ceil(n / ceil(k[i] / f[i]))
			else:
				x = ceil(n / ceil(k[j] / f[j]))
			i = m - 1
			j = i
		j += 1
	i += 1
if x > 0:
	print(x)
else:
	c = []
	for i in range(1, 101):
		j = 0
		b = True
		while j < m and b:
			if not ceil(k[j] / i) == f[j]:
				b = False
			j += 1
		if b:
			c.append(i)
	x = ceil(n / c[0])
	for i in range(len(c)):
		if ceil(n / c[i]) != x:
			x = -1
			break
	print(x)


import math

def find_3():
	etazh = []
	for p in range(1, 101):
		if all(((memory[0] + p - 1) // p == memory[1] for memory in mass)):
			etazh.append(p)
	return etazh

def find_2():
	etazh = []
	p = 1
	while p < 100:
		for i in range(m):
			if math.ceil(mass[i][0] / p) != mass[i][1]:
				p += 1
				break
			elif i == m - 1:
				etazh.append(p)
				p += 1
	return etazh

def find_1():
	etazh = []
	for p in range(100):
		suit = True
		for i in range(m):
			if math.ceil(mass[i][0] / p) != mass[i][1]:
				suit = False
				break
		if suit:
			etazh.append(p)
	return etazh
(n, m) = map(int, input().split())
mass = []
for i in range(m):
	mass.append(list(map(int, input().split())))
etazh = find_3()
if all(((n + x - 1) // x == (n + etazh[0] - 1) // etazh[0] for x in etazh)):
	print((n + etazh[0] - 1) // etazh[0])
else:
	print(-1)


(n, m) = map(int, input().split())
a = [0] * m
for i in range(m):
	a[i] = list(map(int, input().split()))
	a[i][0] -= 1
	a[i][1] -= 1
n -= 1
canbe = set()
last = 0
for i in range(1, 200):
	good = 1
	for j in range(m):
		k = a[j][0]
		f = a[j][1]
		if not i * f <= k <= i * (f + 1) - 1:
			good = 0
	if good:
		canbe.add(n // i)
		last = n // i + 1
if len(canbe) == 1:
	print(last)
else:
	print(-1)


(n, m) = list(map(int, input().split()))
k = []
f = []
for i in range(m):
	(u, p) = list(map(int, input().split()))
	k.append(u)
	f.append(p)

def ok(x):
	for i in range(m):
		if (k[i] - 1) // x + 1 != f[i]:
			return False
	return True
a = []
for i in range(1, 101):
	if ok(i):
		a.append((n - 1) // i + 1)
if len(list(set(a))) == 1:
	print(a[0])
else:
	print(-1)


from math import ceil

class Floor:

	def __init__(self):
		(self.n, self.m) = tuple(map(int, input().split()))
		self.k = []
		self.f = []
		for i in range(self.m):
			s = input().split()
			self.k.append(int(s[0]))
			self.f.append(int(s[1]))

	def check(self, floor):
		for i in range(self.m):
			fl = int(ceil(self.k[i] / floor))
			if fl != self.f[i]:
				return False
		return True

	def solve(self):
		x = -1
		fl = -1
		was = False
		for i in range(1, 101):
			if self.check(i):
				if not was:
					x = int(ceil(self.n / i))
					was = True
				else:
					y = int(ceil(self.n / i))
					if y != x:
						print(-1)
						return
		print(x)
ans = Floor()
ans.solve()


import math
import os
(x, y) = [int(i) for i in input().split()]
if y == 0:
	if x == 1:
		print(1)
	else:
		print(-1)
	exit(0)
a = []
min = 0
max = 10 ** 6
for i in range(y):
	(k, f) = [int(i) for i in input().split()]
	if f == 1:
		if x <= k:
			print(1)
			exit(0)
		else:
			nmax = 10 * 6
			nmin = k
	else:
		if k % (f - 1) == 0:
			nmax = k // (f - 1) - 1
		else:
			nmax = math.floor(k / (f - 1))
		nmin = math.ceil(k / f)
	if nmin > min:
		min = nmin
	if nmax < max:
		max = nmax
	if min == max:
		print(math.ceil(x / min))
		exit(0)
first = math.ceil(x / min)
for i in range(min + 1, max + 1):
	if math.ceil(x / i) != first:
		print(-1)
		exit(0)
print(first)


(n, m) = [int(i) for i in input().split()]
mn = 10 ** 5
mx = 1
n -= 1
for i in range(m):
	(x, y) = [int(i) for i in input().split()]
	x -= 1
	y -= 1
	if y != 0:
		mn = min(mn, x // y)
	mx = max(mx, [(x + y) // (y + 1), x // (y + 1) + 1][x % (y + 1) == 0])
a = n // mx
for i in range(mx + 1, mn + 1):
	if a != n // i:
		print(-1)
		exit()
print(a + 1)


(n, m) = map(int, input().split())
data = []
fl = [0] * 1000000
an = -1
f = 0
for i in range(m):
	data += [list(map(int, input().split()))]
	fl[data[i][0]] = data[i][1]
	if data[i][0] == n:
		an = data[i][1]
	f = max(data[i][1], f)
if an != -1:
	print(an)
	exit(0)
data.sort()
an = []
t = True
for i in range(m):
	if data[i][0] != data[i][1]:
		t = False
if t:
	an += [n]
for k in range(2, 10001):
	t = True
	for i in range(m):
		f = data[i][0] // k + min(1, data[i][0] % k)
		if data[i][1] != f:
			t = False
			break
	if not t:
		continue
	an += [n // k + min(1, n % k)]
if len(set(an)) == 1:
	print(an[0])
else:
	print(-1)


(n, m) = map(int, input().split())
list1 = []
ans = set()
if n == 1:
	print(1)
else:
	for i in range(m):
		list1.append(list(map(int, input().split())))
	for i in range(1, 101):
		if len(ans) > 1:
			print(-1)
			break
		for j in range(len(list1)):
			if (list1[j][0] - 1) // i + 1 != list1[j][1]:
				break
		else:
			ans.add((n - 1) // i + 1)
	else:
		if len(ans) == 1:
			print(*list(ans))
		else:
			print(-1)


(n, m) = list(map(int, input().split()))
k = [0] * m
f = [0] * m
l = 1
r = 100
for i in range(m):
	(k[i], f[i]) = list(map(int, input().split()))
for i in range(m):
	fl = True
	for kol in range(l, r + 1):
		ch = k[i] - (f[i] - 1) * kol
		if ch > 0 and ch <= kol:
			if fl:
				l = kol
				fl = False
		elif not fl:
			r = kol - 1
			break
	if r - l == 0:
		print((n + r - 1) // r)
		break
else:
	kok = (n + r - 1) // r
	for kol in range(l, r):
		if kok != (n + kol - 1) // kol:
			print(-1)
			break
	else:
		print(kok)


(n, m) = map(int, input().split())
kv = [-1] * 101
for i in range(m):
	(x, y) = map(int, input().split())
	kv[x - 1] = y - 1
res = []
for i in range(1, 102):
	check = True
	for j in range(1, 101):
		if kv[j] != -1 and j // i != kv[j]:
			check = False
	if check:
		res.append(i)
curset = set()
for i in res:
	curset.add((n - 1) // i + 1)
if len(curset) == 1:
	print(*list(curset))
else:
	print(-1)


import math

class TaskA:

	def __init__(self):
		s = input().split()
		(self.n, self.m) = (int(s[0]), int(s[1]))
		self.k = list()
		self.f = list()
		for i in range(self.m):
			st = input().split()
			self.k.append(int(st[0]))
			self.f.append(int(st[1]))

	def Check(self, floor):
		for i in range(self.m):
			fl = int(math.ceil(self.k[i] / floor))
			if fl != self.f[i]:
				return False
		return True

	def Solve(self):
		ans = -1
		fl = -1
		was = False
		for i in range(1, 101):
			if self.Check(i):
				if not was:
					ans = int(math.ceil(self.n / i))
					was = True
				else:
					t = int(math.ceil(self.n / i))
					if t != ans:
						print(-1)
						return
		print(ans)
Solver = TaskA()
Solver.Solve()


(n, m) = map(int, input().split())
k = []
for i in range(m):
	(a, b) = map(int, input().split())
	k.append((a, b))
s = 0
v = 0
for i in range(1, 101):
	l = 0
	for t in k:
		if t[0] / i > t[1] or t[0] / i <= t[1] - 1:
			l = 1
			break
	if l == 0:
		x = (n - 1) // i + 1
		if v == 0:
			v = x
		if v != x:
			v = -1
if v == 0:
	v = -1
print(v)


(n, m) = map(int, input().split())
e = []
for i in range(m):
	e.append(list(map(int, input().split())))
check = False
if m == 0 and n != 1:
	print(-1)
	exit(0)
ans = []
for i in range(1, 101):
	check = True
	for j in range(0, m):
		if (e[j][0] + i - 1) // i != e[j][1]:
			check = False
			break
	if check:
		ans.append(i)
minimum = (n + ans[0] - 1) // ans[0]
check = True
for i in range(1, len(ans)):
	if (n + ans[i] - 1) // ans[i] != minimum:
		check = False
		break
if check:
	print(minimum)
else:
	print(-1)


t = 1
for qwe in range(t):
	(n, m) = map(int, input().split())
	listt = []
	for i in range(m):
		(k, f1) = map(int, input().split())
		ttup = (k, f1)
		listt.append(ttup)
	listt.sort(key=lambda a: (a[1], a[0]))
	listtans = set()
	for kol in range(1, 101):
		for i in listt:
			if not (i[1] * kol >= i[0] and i[0] > i[1] * kol - kol):
				break
		else:
			listtans.add((n + kol - 1) // kol)
	if len(listtans) == 1:
		print(*listtans)
	else:
		print(-1)


(n, m) = map(int, input().split())
a = [tuple(map(int, input().split())) for i in range(m)]
ans = set()
for i in range(1, 101):
	can = True
	for (k, f) in a:
		if (k + i - 1) // i != f:
			can = False
			break
	if can:
		ans.add((n + i - 1) // i)
if len(ans) == 1:
	print(ans.pop())
else:
	print('-1')


(n, m) = list(map(int, input().split()))
v = []
for i in range(m):
	v.append(list(map(int, input().split())))
ans = []
for i in range(1, 101):
	o = True
	for p in v:
		if (p[0] - 1) // i != p[1] - 1:
			o = False
			break
	if o:
		if not (n - 1) // i + 1 in ans:
			ans.append((n - 1) // i + 1)
if len(ans) == 1:
	print(ans[0])
else:
	print(-1)


(res, m) = map(int, input().split())
mass = []
if res == 1:
	print(1)
	exit()
if m == 0:
	print(-1)
	exit()
for i in range(m):
	(k, ne) = map(int, input().split())
	mass += [[k, ne]]
s = -1
for i in range(1, 1001):
	r = 1
	for i2 in range(m):
		k = mass[i2][0]
		ne = mass[i2][1]
		x = 0
		if k % i != 0:
			x = 1
		if k // i + x != ne:
			r = 0
			break
	if r:
		x = 0
		if res % i != 0:
			x = 1
		if res // i + x != s and s != -1:
			print(-1)
			exit()
		s = res // i + x
print(s)


k = []
(n, m) = map(int, input().split(' '))
for i in range(m):
	(x, y) = map(int, input().split(' '))
	k.append([x, y])

def ok(x):
	for i in k:
		if (i[0] - 1) // x + 1 != i[1]:
			return False
	return True
poss = []
for x in range(1, 101):
	if ok(x):
		poss.append((n - 1) // x + 1)
if len(list(set(poss))) == 1:
	print(poss[0])
else:
	print(-1)


(n, m) = map(int, input().split())
ans = -1
k = []
f = []
for i in range(m):
	(flat, level) = map(int, input().split())
	k.append(flat)
	f.append(level)
mainflag = True
for count in range(1, 101):
	flag = True
	for i in range(m):
		if (k[i] + count - 1) // count != f[i]:
			flag = False
			break
	if flag and ans != -1 and ((n + count - 1) // count != (n + ans - 1) // ans):
		mainflag = False
	elif flag:
		ans = count
if mainflag:
	print((n + ans - 1) // ans)
else:
	print(-1)


(n, m) = map(int, input().split())
kf = [tuple(map(int, input().split())) for _ in range(m)]
ans = set()
for i in range(1, 101):
	for (k, f) in kf:
		if (k + i - 1) // i != f:
			break
	else:
		ans.add((n + i - 1) // i)
if len(ans) == 1:
	print(list(ans)[0])
else:
	print(-1)


from math import ceil
[n, m] = [int(x) for x in input().split()]
possible = [True] * 110
flats = []
for i in range(0, m):
	flats.append([int(x) for x in input().split()])
for flat in flats:
	for size in range(1, 101):
		if ceil(flat[0] / size) != flat[1]:
			possible[size] = False
ans = -1
for size in range(1, 101):
	if possible[size]:
		possible_floor = ceil(n / size)
		if ans == -1:
			ans = possible_floor
		elif ans != possible_floor:
			print(-1)
			exit()
print(ans)


def first(n, m, line):
	for i in range(0, n):
		(k, f) = list(map(int, input().split()))
		res = []
		for j in range(1, 101):
			if j * f >= k and j * (f - 1) < k:
				res.append(j)
		line.append(res)
		res = []
	return line

def check(n, m, hz):
	for i in range(1, 101):
		dno = 0
		for elem in line:
			if i in elem:
				dno += 1
		if dno == n:
			hz.append(i)
	return hz
(m, n) = list(map(int, input().split()))
line = []
line = first(n, m, line)
hz = []
hz = check(n, m, hz)
ans = []
for element in hz:
	if m % element == 0:
		ans.append(m // element)
	else:
		ans.append(m // element + 1)
smth = ans[0]
answ = 0
for element in ans:
	if element != smth:
		answ = -1
if answ == -1:
	print(answ)
else:
	print(smth)


(n, m) = list(map(int, input().split()))
n = n - 1
et = []
for i in range(m):
	et.append(tuple(map(lambda x: int(x) - 1, input().split())))
et.sort()
res = -1
if n == 0:
	res = 1
elif len(et) == 0:
	pass
else:
	et = [(-1, 0)] + et
	for i in range(len(et) - 1):
		if et[i][0] <= n <= et[i + 1][0] and et[i][1] == et[i + 1][1]:
			res = et[i][1] + 1
			break
	et = et[1:]
	if res == -1 and et[-1][1] != 0:
		y = []
		for i in range(1, et[-1][0] // et[-1][1] + 1):
			fl = True
			for j in range(len(et)):
				if et[j][0] // i != et[j][1]:
					fl = False
					break
			if fl:
				y.append(i)
		y1 = set([n // tmp + 1 for tmp in y])
		if len(y1) == 1:
			res = y1.pop()
print(res)


(n, m) = map(int, input().split())
l = -100
r = 100
for i in range(m):
	(k, f) = map(int, input().split())
	l = max(l, (k + f - 1) // f)
	if f != 1:
		r = min(r, (k - 1) // (f - 1))
if l == r:
	print((n + r - 1) // r)
elif (n + r - 1) // r == (n + l - 1) // l:
	print((n + r - 1) // r)
else:
	print(-1)


(m, n) = map(int, input().split())
canbe = []
for i in range(0, n):
	(numb, et) = map(int, input().split())
	can = []
	for j in range(1, 101):
		if j * et >= numb and j * (et - 1) < numb:
			can += [j]
	canbe += [can]
	can = []
canbeat = []
for i in range(1, 101):
	est = 0
	for el in canbe:
		if i in el:
			est += 1
	if est == n:
		canbeat += [i]
ans = []
for element in canbeat:
	if m % element == 0:
		ans += [m // element]
	else:
		ans += [m // element + 1]
writ = ans[0]
tr = 0
for element in ans:
	if element != writ:
		tr = -1
if tr == -1:
	print(tr)
else:
	print(writ)


from math import ceil

def check(flats_on_level):
	for fl in flats:
		after = ceil(fl[0] / flats_on_level)
		if fl[1] != after:
			return False
	return True
(n, m) = map(int, input().split())
flats = []
for _ in range(m):
	(ki, fi) = map(int, input().split())
	flats.append((ki, fi))
answer = -1
cf = -1
if m == 0 and n == 1:
	print(1)
	exit(0)
for i in range(1, 101):
	if check(i):
		if answer == -1:
			answer = i
			cf = i
		else:
			cf = i
if ceil(n / answer) != ceil(n / cf):
	print(-1)
else:
	print(ceil(n / answer))


def xor(a, b, i):
	if (a - 1) // i == b - 1:
		return True
	elif a < i and b == 1:
		return True
	else:
		return False
dannie = input()
dannie = dannie.split(' ')
level = int(dannie[0])
n = int(dannie[1])
levels = []
if level == 1:
	print(1)
elif n == 0:
	print(-1)
else:
	for i in range(0, n):
		info = input()
		info = info.split(' ')
		levels.append(info)
	fl = True
	i = 1
	count = 0
	while i <= 100 and fl:
		for etaz in levels:
			fl2 = True
			flat = int(etaz[0])
			floor = int(etaz[1])
			if xor(flat, floor, i):
				continue
			else:
				fl2 = False
			if not fl2:
				break
		if not fl2:
			i = i + 1
		elif count == 0 and fl2:
			count += 1
			if level % i == 0:
				answer = int(level / i)
				i = i + 1
			else:
				answer = int(level // i + 1)
				i = i + 1
		elif fl2 and count != 0:
			if level % i == 0:
				answer1 = level / i
			else:
				answer1 = level // i + 1
			if answer1 == answer:
				i = i + 1
				continue
			else:
				print(-1)
				fl = False
		else:
			i += 1
	if fl:
		try:
			print(answer)
		except NameError:
			print(-1)


(n, k) = map(int, input().split())
memories = []
for i in range(k):
	(x, y) = map(int, input().split())
	memories.append((x, y))
suitable = []
m = 1
stop = False
while not stop and (m <= n or len(suitable) == 0):
	suit = True
	for q in memories:
		(x, y) = (q[0], q[1])
		if (x + m - 1) // m < y:
			suit = False
			stop = True
			break
		if (x + m - 1) // m > y:
			suit = False
			m = (x + y - 1) // y
			break
	if suit:
		suitable.append(m)
		m += 1
print((n + suitable[0] - 1) // suitable[0] if len(suitable) > 0 and all([(n + m - 1) // m == (n + suitable[0] - 1) // suitable[0] for m in suitable]) else -1)
(10 + m - 1) // m < 1


FLOW_COUNT = 100
APARTMENT_COUNT = 100
AF_COUNT = 100

def build_for(app_per_flow):
	b = dict()
	for f in range(FLOW_COUNT):
		for a in range(app_per_flow):
			app = f * app_per_flow + a
			if app >= APARTMENT_COUNT:
				return b
			b[app] = f
	return b

def check_for(b, d):
	(app, flow) = d
	return app in b and b[app] == flow
data = input()
d = data.split()
assert len(d) == 2
(n, k) = (int(d[0]) - 1, int(d[1]))
fs = list()
for i in range(k):
	data = input()
	d = data.split()
	assert len(d) == 2
	fs.append((int(d[0]) - 1, int(d[1]) - 1))
(index, res) = (0, 0)
for af in range(AF_COUNT):
	b = build_for(af + 1)
	for d in fs:
		if not check_for(b, d):
			break
	else:
		f = n // (af + 1) + 1
		if index and f != res:
			index = 0
			break
		else:
			index = af + 1
			res = f
if index > 0:
	print('%d' % res)
else:
	print('-1')


(m, n) = map(int, input().split())
arr = []
for i in range(n):
	(a, b) = map(int, input().split())
	arr.append((a, b))
ans = set()
for k in range(1, 150):
	fl = True
	for i in range(n):
		if (arr[i][0] - 1) // k + 1 != arr[i][1]:
			fl = False
			break
	if fl:
		ans.add((m - 1) // k + 1)
if len(ans) == 1:
	for i in ans:
		print(i)
else:
	print(-1)


(n, m) = [int(i) for i in input().split()]
floor_info = [[int(i) for i in input().split()] for j in range(m)]
ans = list(set([(n - 1) // i + 1 for i in range(1, 101) if all([(sub_floor[0] - 1) // i + 1 == sub_floor[1] for sub_floor in floor_info])]))
if len(ans) == 1:
	print(ans[0])
else:
	print(-1)


(n, m) = map(int, input().split())
(ans, flats) = ([], {})
for _ in range(m):
	(flat, floor) = map(int, input().split())
	flats[flat] = floor
for cf in range(1, 101):
	flag = True
	for flat in flats.items():
		if (flat[0] - 1) // cf + 1 != flat[1]:
			flag = False
			break
	if flag:
		ans.append((n - 1) // cf + 1)
if len(list(set(ans))) == 1:
	print(ans[0])
else:
	print(-1)


(n, m) = map(int, input().split())
A = []
B = []
for i in range(m):
	(a, b) = map(int, input().split())
	A.append(a)
	B.append(b)
tmin = 1
tmax = 100
for j in range(m):
	if B[j] == 1 and tmin < A[j]:
		tmin = A[j]
	elif B[j] > 1:
		if tmax > (A[j] - 1) // (B[j] - 1):
			tmax = (A[j] - 1) // (B[j] - 1)
		if A[j] % B[j] == 0 and tmin < A[j] // B[j]:
			tmin = A[j] // B[j]
		elif A[j] % B[j] != 0 and tmin < A[j] // B[j] + 1:
			tmin = A[j] // B[j] + 1
if n % tmax == 0:
	nlow = n // tmax
else:
	nlow = n // tmax + 1
if n % tmin == 0:
	nhigh = n // tmin
else:
	nhigh = n // tmin + 1
if nhigh == nlow:
	print(nhigh)
else:
	print(-1)


(n, m) = map(int, input().split())
n -= 1
k = []
f = []
p = 0
for i in range(m):
	q = list(map(int, input().split()))
	k.append(q[0])
	f.append(q[1])
for i in range(1, 101):
	for j in range(m):
		if (k[j] - 1) // i + 1 != f[j]:
			break
	else:
		if not p:
			p = n // i + 1
		else:
			q = n // i + 1
			if p != q:
				print(-1)
				exit()
print(p)


import math
(n, m) = map(int, input().split())
znach = range(1, 200)
for i in range(m):
	(k, f) = map(int, input().split())
	if f == 1:
		a = range(math.ceil(k / f), 200)
	else:
		niz = math.ceil(k / f)
		verh = math.floor((k - 1) / (f - 1))
		a = range(niz, verh + 1)
	znach = list(set(a) & set(znach))
if len(znach) == 1:
	if n % znach[0] == 0:
		print(n // znach[0])
	else:
		print(n // znach[0] + 1)
else:
	a = []
	for i in range(len(znach)):
		if n % znach[i] == 0:
			a.append(n // znach[i])
		else:
			a.append(n // znach[i] + 1)
	a = list(set(a))
	if len(a) > 1:
		print(-1)
	else:
		print(a[0])


(n, m) = (int(x) for x in input().split())
flat = [0 for x in range(m)]
floor = [0 for x in range(m)]
a = set()
ans = -1
for i in range(m):
	(flat[i], floor[i]) = (int(x) for x in input().split())
for i in range(1, 101, 1):
	tf = 1
	for j in range(m):
		if (flat[j] - 1) // i != floor[j] - 1:
			tf = 0
			break
	if tf == 1:
		num = (n - 1) // i + 1
		if len(a) == 0:
			a.add(num)
			ans = num
		elif num not in a:
			ans = -1
			break
print(ans)


(n, m) = map(int, input().split())
mas = []
for i in range(m):
	(x, y) = map(int, input().split())
	mas.append([x, y])
vivod = []
for num in range(1, 101):
	flag = True
	for i in range(m):
		if not ((mas[i][1] - 1) * num < mas[i][0] and mas[i][1] * num >= mas[i][0]):
			flag = False
			break
	if flag:
		vivod.append(num)
for i in range(len(vivod)):
	vivod[i] = (n - 1) // vivod[i] + 1
x = vivod[0]
for i in vivod:
	if i != x:
		print(-1)
		exit()
print(x)


from math import ceil

def main():
	(n, m) = map(int, input().split())
	d = []
	for i in range(m):
		d.append(list(map(int, input().split())))
	fl = []
	for i in range(1, 101):
		for j in range(m):
			(k, f) = (d[j][0], d[j][1])
			if ceil(k / i) != f:
				break
		else:
			fl.append(i)
	if len(fl) > 1:
		ans1 = ceil(n / fl[0])
		ans2 = -1
		for i in range(1, len(fl)):
			ans2 = ceil(n / fl[i])
			if ans1 != ans2:
				print(-1)
				break
		else:
			print(ans1)
	else:
		print((n + fl[0] - 1) // fl[0])
main()


data = input().strip().split()
a = int(data[0])
b = int(data[1])
c = []
r = []
max = 0
for i in range(b):
	data = input().strip().split()
	c.append([int(data[0]), int(data[1])])
	if int(data[0]) > max:
		max = int(data[0])
for i in range(1, 1000):
	flag = True
	for j in range(len(c)):
		n = c[j][0] // i
		if not c[j][0] % i == 0:
			n += 1
		if n == c[j][1]:
			continue
		else:
			flag = False
			break
	if flag:
		r.append(i)
r1 = []
for i in r:
	n = a // i
	if not a % i == 0:
		n += 1
	r1.append(n)
r1 = list(set(r1))
if len(r1) != 1:
	print('-1')
else:
	print(r1[0])


a = input().split()
m = [0] * int(a[1])
k = [0] * int(a[1])
ans = -1
for i in range(int(a[1])):
	b = input().split()
	m[i] = int(b[0])
	k[i] = int(b[1])
for i in range(1, 101):
	f = True
	d = 0
	for j in range(int(a[1])):
		if m[j] % i == 0:
			d = m[j] // i
		else:
			d = m[j] // i + 1
		if d != k[j]:
			f = False
			break
	if f:
		if int(a[0]) % i == 0:
			x = int(a[0]) // i
		else:
			x = int(a[0]) // i + 1
		if ans == -1:
			ans = x
		elif ans != x:
			print(-1)
			exit(0)
print(ans)


(n, m) = map(int, input().split())
k = [0] * 500
f = [0] * 500
for i in range(m):
	(k[i], f[i]) = map(int, input().split())
vars = set()
for cnt in range(1, 201):
	flag = 1
	for i in range(m):
		if (k[i] - 1) // cnt != f[i] - 1:
			flag = 0
			break
	if flag:
		vars.add((n - 1) // cnt + 1)
if n == 1:
	ans = 1
else:
	ans = -1 if len(vars) > 1 else max(vars)
print(ans)


(n, m) = [int(x) for x in input().split()]
data = []
for i in range(m):
	(k, f) = [int(x) for x in input().split()]
	data.append((k - 1, f - 1))
ans = set()
for x in range(1, 101):
	for elem in data:
		if elem[0] // x != elem[1]:
			break
	else:
		ans.add((n - 1) // x + 1)
if len(ans) == 1:
	print(ans.pop())
else:
	print(-1)


l = []
f = fn = 0
[n, m] = map(int, input().split())
for i in range(m):
	l.append(list(map(int, input().split())))
for i in range(1, 101):
	for j in l:
		if (j[0] // i if j[0] % i == 0 else j[0] // i + 1) != j[1]:
			break
	else:
		if f == 0:
			f = i
			fn = n // i if n % i == 0 else n // i + 1
		elif fn != (n // i if n % i == 0 else n // i + 1):
			print(-1)
			exit()
print(fn)


import math

def f(m):
	global h
	f = True
	for i in range(len(h)):
		for j in h[i]:
			if not (j <= i * m and j > (i - 1) * m):
				f = False
	return f
(n, m) = map(int, input().split())
h = [[] for i in range(110)]
for i in range(m):
	(a, b) = map(int, input().split())
	h[b].append(a)
k = 0
ans = []
for i in range(1, 110):
	if f(i):
		k += 1
		ans.append(i)
fl = False
for i in range(len(h)):
	for j in h[i]:
		if j == n:
			fl = True
			ans1 = i
if fl:
	print(ans1)
elif m == 0 and n == 1:
	print(1)
elif k > 1:
	pr = math.ceil(n / ans[0])
	fl1 = True
	for i in range(1, len(ans)):
		if pr != math.ceil(n / ans[i]):
			fl1 = False
	if not fl1:
		print(-1)
	else:
		print(pr)
elif k < 1:
	print(-1)
else:
	print(math.ceil(n / ans[0]))


import math
(n, q) = map(int, input().split())
lst = []
for i in range(q):
	(x, y) = map(int, input().split())
	lst.append((x, y))
ans = set()
for no_of_floors in range(1, 101):
	flag = 1
	for (k, f) in lst:
		temp_floor = math.ceil(k / no_of_floors)
		if temp_floor != f:
			flag = 0
	if flag:
		temp = math.ceil(n / no_of_floors)
		ans.add(temp)
if len(ans) != 1:
	print(-1)
else:
	print(*ans)


from math import floor, ceil
(n, m) = list(map(int, input().split()))
(x1, x2) = (1, 100)
for i in range(m):
	(a, b) = list(map(int, input().split()))
	if ceil(a / b) > x1:
		x1 = ceil(a / b)
	if b > 1:
		if floor((a - 1) / (b - 1)) < x2:
			x2 = floor((a - 1) / (b - 1))
get_floor = lambda x: (n - 1) // x + 1
if get_floor(x1) == get_floor(x2):
	print(get_floor(x1))
else:
	print(-1)


from math import ceil

def task():
	a = list(map(int, input().split()))
	n = a[0]
	m = a[1]
	answer = -1
	b = [list()] * m
	cf = 0
	for i in range(0, m):
		b[i] = list(map(int, input().split()))
	for i in range(1, 101):
		cf = i
		for j in range(0, m):
			q = b[j][0]
			e = b[j][1]
			if ceil(q / cf) != e:
				cf = -1
				break
		if cf != -1:
			if answer != -1 and ceil(n / cf) != answer:
				print(-1)
				return
			else:
				answer = ceil(n / cf)
	print(answer)
task()


(n, m) = map(int, input().split())
u = []
ook = True
ans = -1
for i in range(m):
	u.append(tuple(map(int, input().split())))
for cf in range(1, 101):
	ok = True
	for i in range(m):
		if (u[i][0] - 1) // cf + 1 != u[i][1]:
			ok = False
			break
	if ok and ans != -1 and ((n - 1) // cf + 1 != ans):
		print(-1)
		ook = False
		break
	elif ok:
		ans = (n - 1) // cf + 1
if ook:
	print(ans)


(n, m) = map(int, input().split())
l = set()
s = {i for i in range(1, 101)}
b = False
for i in range(m):
	(k, f) = map(int, input().split())
	if k == n:
		print(f)
		b = True
		break
	j = 1
	if f == 1:
		l = {i for i in range(k, 101)}
	else:
		while j <= (k - j) // (f - 1):
			if (k - j) % (f - 1) == 0:
				l.add((k - j) // (f - 1))
				j += f - 1
			else:
				j += 1
	s &= l
	l.clear()
a = -1
if b == False:
	t = True
	for j in s:
		if a == -1:
			a = (n - 1) // j
		elif (n - 1) // j != a:
			print(-1)
			t = False
			break
	if t == True:
		print(a + 1)


import math
(n, m) = [int(i) for i in input().split()]
k = [[int(i) for i in input().split()] for j in range(m)]
z = True
p = 0
a = -1
while p != 101:
	z = True
	p += 1
	for i in range(m):
		if math.ceil(k[i][0] / p) != k[i][1]:
			z = False
			break
	if z and a == -1:
		a = math.ceil(n / p)
	if (a != -1) & z & (math.ceil(n / p) != a):
		a = -1
		break
print(a)


(n, m) = map(int, input().split())
min_ = 10000
max_ = 0
for i in range(m):
	(k, f) = map(int, input().split())
	if f > 1:
		min_ = min(k / (f - 1), min_)
	max_ = max(k / f, max_)
(min_, max_) = (max_, min_)
if min_ != int(min_):
	min_ += 1
min_ = int(min_)
if max_ != int(max_):
	max_ += 1
max_ = int(max_)
s = set()
for i in range(max(1, min_), max_):
	b = n // i
	if n % i != 0:
		b += 1
	s.add(b)
if len(s) == 1:
	print(b)
else:
	print(-1)


(n, m) = map(int, input().split())
k = []
for i in range(m):
	k.append([])
	k[i] = list(map(int, input().split()))
answ = []
for i in range(1, 101):
	test = True
	for j in range(m):
		t = (k[j][0] + i - 1) // i
		if t != k[j][1]:
			test = False
	if test:
		answ.append(i)
if len(answ) == 0:
	print(-1)
	exit(0)
t = []
for i in answ:
	t.append((n + i - 1) // i)
if min(t) != max(t):
	print(-1)
	exit(0)
print(t[0])


(n, m) = map(int, input().split())
a = [0] * 100
for i in range(m):
	(l, k) = map(int, input().split())
	if k == 1:
		b = l
		c = 100
	else:
		c = (l - 1) // (k - 1)
		b = l // k + bool(l % k)
	for j in range(b - 1, c):
		a[j] += 1
x = 0
y = 0
b = [0] * 100
for i in range(100):
	if a[i] == m:
		x += 1
		y = i + 1
		b[i] = (n - 1) // y + 1
		if b[i] == b[i - 1] and i > 0:
			x -= 1
if x != 1:
	print(-1)
else:
	print((n - 1) // y + 1)


import math
(n, m) = map(int, input().split())
dic = {}
for i in range(1, 101):
	dic[i] = []
for i in range(m):
	(k, f) = map(int, input().split())
	dic[f].append(k)
ans = []
for f in range(1, 101):
	f1 = 0
	for i in dic:
		for j in dic[i]:
			if j > f * (i - 1) and j <= f * i:
				continue
			else:
				f1 = 1
				break
		if f1 == 1:
			break
	if f1 == 0:
		ans.append(f)
if len(ans) >= 1:
	p = math.ceil(n / ans[0])
	f = 0
	for i in range(len(ans)):
		if math.ceil(n / ans[i]) == p:
			continue
		else:
			f = 1
			break
	if f == 1:
		print(-1)
	else:
		print(p)
else:
	print(-1)


(n, m) = map(int, input().split())
data = []
for i in range(0, m):
	data.append(list(map(int, input().split())))
if m == 0 and n != 1:
	print(-1)
else:
	ans = []
	for i in range(1, 102):
		mark = 1
		for j in range(0, m):
			if (data[j][0] + i - 1) // i != data[j][1]:
				mark = 0
				break
		if mark:
			ans.append(i)
	for_print = (n + ans[0] - 1) // ans[0]
	mark = 1
	for i in range(1, len(ans)):
		if (n + ans[i] - 1) // ans[i] != for_print:
			mark = 0
			break
	if mark:
		print(for_print)
	else:
		print(-1)