pub trait Zero: PartialEq + Sized {
    fn zero() -> Self;
    #[inline]
    fn is_zero(&self) -> bool {
        self == &Self::zero()
    }
}
pub trait One: PartialEq + Sized {
    fn one() -> Self;
    #[inline]
    fn is_one(&self) -> bool {
        self == &Self::one()
    }
}
macro_rules ! zero_one_impls { ($ ({ $ Trait : ident $ method : ident $ ($ t : ty) *, $ e : expr }) *) => { $ ($ (impl $ Trait for $ t { # [inline] fn $ method () -> Self { $ e } }) *) * } ; }
zero_one_impls ! ({ Zero zero u8 u16 u32 u64 usize i8 i16 i32 i64 isize u128 i128 , 0 } { Zero zero f32 f64 , 0. } { One one u8 u16 u32 u64 usize i8 i16 i32 i64 isize u128 i128 , 1 } { One one f32 f64 , 1. }) ;
#[macro_export]
macro_rules ! min { ($ e : expr) => { $ e } ; ($ e : expr , $ ($ es : expr) ,+) => { std :: cmp :: min ($ e , min ! ($ ($ es) ,+)) } ; }
#[macro_export]
macro_rules ! chmin { ($ dst : expr , $ ($ src : expr) ,+) => { { let x = std :: cmp :: min ($ dst , min ! ($ ($ src) ,+)) ; $ dst = x ; } } ; }
#[macro_export]
macro_rules ! max { ($ e : expr) => { $ e } ; ($ e : expr , $ ($ es : expr) ,+) => { std :: cmp :: max ($ e , max ! ($ ($ es) ,+)) } ; }
#[macro_export]
macro_rules ! chmax { ($ dst : expr , $ ($ src : expr) ,+) => { { let x = std :: cmp :: max ($ dst , max ! ($ ($ src) ,+)) ; $ dst = x ; } } ; }
pub trait IterScan: Sized {
    type Output;
    fn scan<'a, I: Iterator<Item = &'a str>>(iter: &mut I) -> Option<Self::Output>;
}
pub trait MarkedIterScan: Sized {
    type Output;
    fn mscan<'a, I: Iterator<Item = &'a str>>(self, iter: &mut I) -> Option<Self::Output>;
}
#[derive(Clone, Debug)]
pub struct Scanner<'a> {
    iter: std::str::SplitAsciiWhitespace<'a>,
}
mod scanner_impls {
    use super::*;
    impl<'a> Scanner<'a> {
        #[inline]
        pub fn new(s: &'a str) -> Self {
            let iter = s.split_ascii_whitespace();
            Self { iter }
        }
        #[inline]
        pub fn scan<T: IterScan>(&mut self) -> <T as IterScan>::Output {
            <T as IterScan>::scan(&mut self.iter).expect("scan error")
        }
        #[inline]
        pub fn mscan<T: MarkedIterScan>(&mut self, marker: T) -> <T as MarkedIterScan>::Output {
            marker.mscan(&mut self.iter).expect("scan error")
        }
        #[inline]
        pub fn scan_vec<T: IterScan>(&mut self, size: usize) -> Vec<<T as IterScan>::Output> {
            (0..size)
                .map(|_| <T as IterScan>::scan(&mut self.iter).expect("scan error"))
                .collect()
        }
        #[inline]
        pub fn iter<'b, T: IterScan>(&'b mut self) -> ScannerIter<'a, 'b, T> {
            ScannerIter {
                inner: self,
                _marker: std::marker::PhantomData,
            }
        }
    }
    macro_rules ! iter_scan_impls { ($ ($ t : ty) *) => { $ (impl IterScan for $ t { type Output = Self ; # [inline] fn scan <'a , I : Iterator < Item = &'a str >> (iter : & mut I) -> Option < Self > { iter . next () ?. parse ::<$ t > () . ok () } }) * } ; }
    iter_scan_impls ! (char u8 u16 u32 u64 usize i8 i16 i32 i64 isize f32 f64 u128 i128 String) ;
    macro_rules ! iter_scan_tuple_impl { ($ ($ T : ident) *) => { impl <$ ($ T : IterScan) ,*> IterScan for ($ ($ T ,) *) { type Output = ($ (<$ T as IterScan >:: Output ,) *) ; # [inline] fn scan <'a , It : Iterator < Item = &'a str >> (_iter : & mut It) -> Option < Self :: Output > { Some (($ (<$ T as IterScan >:: scan (_iter) ?,) *)) } } } ; }
    iter_scan_tuple_impl!();
    iter_scan_tuple_impl!(A);
    iter_scan_tuple_impl ! (A B) ;
    iter_scan_tuple_impl ! (A B C) ;
    iter_scan_tuple_impl ! (A B C D) ;
    iter_scan_tuple_impl ! (A B C D E) ;
    iter_scan_tuple_impl ! (A B C D E F) ;
    iter_scan_tuple_impl ! (A B C D E F G) ;
    iter_scan_tuple_impl ! (A B C D E F G H) ;
    iter_scan_tuple_impl ! (A B C D E F G H I) ;
    iter_scan_tuple_impl ! (A B C D E F G H I J) ;
    iter_scan_tuple_impl ! (A B C D E F G H I J K) ;
    pub struct ScannerIter<'a, 'b, T> {
        inner: &'b mut Scanner<'a>,
        _marker: std::marker::PhantomData<fn() -> T>,
    }
    impl<'a, 'b, T: IterScan> Iterator for ScannerIter<'a, 'b, T> {
        type Item = <T as IterScan>::Output;
        #[inline]
        fn next(&mut self) -> Option<Self::Item> {
            <T as IterScan>::scan(&mut self.inner.iter)
        }
    }
}
pub mod marker {
    use super::*;
    use std::{iter::FromIterator, marker::PhantomData};
    #[derive(Debug, Copy, Clone)]
    pub struct Usize1;
    impl IterScan for Usize1 {
        type Output = usize;
        #[inline]
        fn scan<'a, I: Iterator<Item = &'a str>>(iter: &mut I) -> Option<Self::Output> {
            Some(<usize as IterScan>::scan(iter)?.checked_sub(1)?)
        }
    }
    #[derive(Debug, Copy, Clone)]
    pub struct Chars;
    impl IterScan for Chars {
        type Output = Vec<char>;
        #[inline]
        fn scan<'a, I: Iterator<Item = &'a str>>(iter: &mut I) -> Option<Self::Output> {
            Some(iter.next()?.chars().collect())
        }
    }
    #[derive(Debug, Copy, Clone)]
    pub struct CharsWithBase(pub char);
    impl MarkedIterScan for CharsWithBase {
        type Output = Vec<usize>;
        #[inline]
        fn mscan<'a, I: Iterator<Item = &'a str>>(self, iter: &mut I) -> Option<Self::Output> {
            Some(
                iter.next()?
                    .chars()
                    .map(|c| (c as u8 - self.0 as u8) as usize)
                    .collect(),
            )
        }
    }
    #[derive(Debug, Copy, Clone)]
    pub struct Collect<T: IterScan, B: FromIterator<<T as IterScan>::Output>> {
        size: usize,
        _marker: PhantomData<fn() -> (T, B)>,
    }
    impl<T: IterScan, B: FromIterator<<T as IterScan>::Output>> Collect<T, B> {
        pub fn new(size: usize) -> Self {
            Self {
                size,
                _marker: PhantomData,
            }
        }
    }
    impl<T: IterScan, B: FromIterator<<T as IterScan>::Output>> MarkedIterScan for Collect<T, B> {
        type Output = B;
        #[inline]
        fn mscan<'a, I: Iterator<Item = &'a str>>(self, iter: &mut I) -> Option<Self::Output> {
            Some(
                (0..self.size)
                    .map(|_| <T as IterScan>::scan(iter).expect("scan error"))
                    .collect::<B>(),
            )
        }
    }
}
/// return: [(start, length)]
pub fn run_length_encoding<T: PartialEq>(v: &[T]) -> Vec<(usize, usize)> {
    let mut res = Vec::new();
    for (i, a) in v.iter().enumerate() {
        if let Some((start, len)) = res.last_mut() {
            if &v[*start] == a {
                *len += 1;
                continue;
            }
        }
        res.push((i, 1));
    }
    res
}
fn main() {
    #![allow(unused_imports, unused_macros)]
    use std::io::{stdin, stdout, BufWriter, Read as _, Write as _};
    let mut _in_buf = Vec::new();
    stdin().read_to_end(&mut _in_buf).expect("io error");
    let _in_buf = unsafe { String::from_utf8_unchecked(_in_buf) };
    let mut scanner = Scanner::new(&_in_buf);
    macro_rules ! scan { () => { scan ! (usize) } ; (($ ($ t : tt) ,*)) => { ($ (scan ! ($ t)) ,*) } ; ([$ t : tt ; $ len : expr]) => { (0 ..$ len) . map (| _ | scan ! ($ t)) . collect ::< Vec < _ >> () } ; ([$ t : ty ; $ len : expr]) => { scanner . scan_vec ::<$ t > ($ len) } ; ([$ t : ty]) => { scanner . iter ::<$ t > () } ; ({ $ e : expr }) => { scanner . mscan ($ e) } ; ($ t : ty) => { scanner . scan ::<$ t > () } ; }
    let _out = stdout();
    let mut _out = BufWriter::new(_out.lock());
    macro_rules ! print { ($ ($ arg : tt) *) => (:: std :: write ! (_out , $ ($ arg) *) . expect ("io error")) }
    macro_rules ! println { ($ ($ arg : tt) *) => (:: std :: writeln ! (_out , $ ($ arg) *) . expect ("io error")) }
    macro_rules! echo {
        ($ iter : expr) => {
            echo!($iter, '\n')
        };
        ($ iter : expr , $ sep : expr) => {
            let mut iter = $iter.into_iter();
            if let Some(item) = iter.next() {
                print!("{}", item);
            }
            for item in iter {
                print!("{}{}", $sep, item);
            }
            println!();
        };
    }
    let n = scan!();
    let s = scan!({ marker::CharsWithBase('0') });
    let run: Vec<_> = run_length_encoding(&s)
        .into_iter()
        .filter(|t| s[t.0] == 1)
        .collect();
    let mut st = vec![(0, n, 0, run.len())];
    let mut ans = 0u64;
    while let Some((l, r, li, ri)) = st.pop() {
        if l >= r || li >= ri {
            continue;
        }
        let m = run[li..ri].iter().map(|t| t.1).max().unwrap_or_default();
        let mxi: Vec<_> = (li..ri).filter(|&i| run[i].1 == m).collect();
        let m = m as u64;
        let k = mxi.len();
        let a = run[mxi[0]].0 as u64 - l as u64;
        let c = r as u64 - (run[mxi[k - 1]].0 as u64 + m);
        ans += (a + c) * m * (m + 1) / 2;
        ans += (a + c) * m * m * (k as u64 - 1);
        ans += k as u64 * m * (m + 1) * (m + 2) / 6;
        ans += a * c * m;
        for (i, j) in mxi.iter().cloned().zip(mxi.iter().cloned().skip(1)) {
            let d = (run[j].0 - (run[i].0 + m as usize)) as u64;
            ans += d * m as u64 * (m + 1);
            ans += d * m * (run[i].0 - l + r - (run[j].0 + m as usize)) as u64;
            ans += m * m * m - (m - 1) * m * (2 * m - 1) / 6;
            st.push((run[i].0 + m as usize, run[j].0, i + 1, j));
        }
        st.push((l, run[mxi[0]].0, li + 1, mxi[0]));
        st.push((run[mxi[k - 1]].0 + m as usize, r, mxi[k - 1] + 1, ri));
    }
    println!("{}", ans);
}


pub trait Zero: PartialEq + Sized {
    fn zero() -> Self;
    #[inline]
    fn is_zero(&self) -> bool {
        self == &Self::zero()
    }
}
pub trait One: PartialEq + Sized {
    fn one() -> Self;
    #[inline]
    fn is_one(&self) -> bool {
        self == &Self::one()
    }
}
macro_rules ! zero_one_impls { ($ ({ $ Trait : ident $ method : ident $ ($ t : ty) *, $ e : expr }) *) => { $ ($ (impl $ Trait for $ t { # [inline] fn $ method () -> Self { $ e } }) *) * } ; }
zero_one_impls ! ({ Zero zero u8 u16 u32 u64 usize i8 i16 i32 i64 isize u128 i128 , 0 } { Zero zero f32 f64 , 0. } { One one u8 u16 u32 u64 usize i8 i16 i32 i64 isize u128 i128 , 1 } { One one f32 f64 , 1. }) ;
#[macro_export]
macro_rules ! min { ($ e : expr) => { $ e } ; ($ e : expr , $ ($ es : expr) ,+) => { std :: cmp :: min ($ e , min ! ($ ($ es) ,+)) } ; }
#[macro_export]
macro_rules ! chmin { ($ dst : expr , $ ($ src : expr) ,+) => { { let x = std :: cmp :: min ($ dst , min ! ($ ($ src) ,+)) ; $ dst = x ; } } ; }
#[macro_export]
macro_rules ! max { ($ e : expr) => { $ e } ; ($ e : expr , $ ($ es : expr) ,+) => { std :: cmp :: max ($ e , max ! ($ ($ es) ,+)) } ; }
#[macro_export]
macro_rules ! chmax { ($ dst : expr , $ ($ src : expr) ,+) => { { let x = std :: cmp :: max ($ dst , max ! ($ ($ src) ,+)) ; $ dst = x ; } } ; }
pub trait IterScan: Sized {
    type Output;
    fn scan<'a, I: Iterator<Item = &'a str>>(iter: &mut I) -> Option<Self::Output>;
}
pub trait MarkedIterScan: Sized {
    type Output;
    fn mscan<'a, I: Iterator<Item = &'a str>>(self, iter: &mut I) -> Option<Self::Output>;
}
#[derive(Clone, Debug)]
pub struct Scanner<'a> {
    iter: std::str::SplitAsciiWhitespace<'a>,
}
mod scanner_impls {
    use super::*;
    impl<'a> Scanner<'a> {
        #[inline]
        pub fn new(s: &'a str) -> Self {
            let iter = s.split_ascii_whitespace();
            Self { iter }
        }
        #[inline]
        pub fn scan<T: IterScan>(&mut self) -> <T as IterScan>::Output {
            <T as IterScan>::scan(&mut self.iter).expect("scan error")
        }
        #[inline]
        pub fn mscan<T: MarkedIterScan>(&mut self, marker: T) -> <T as MarkedIterScan>::Output {
            marker.mscan(&mut self.iter).expect("scan error")
        }
        #[inline]
        pub fn scan_vec<T: IterScan>(&mut self, size: usize) -> Vec<<T as IterScan>::Output> {
            (0..size)
                .map(|_| <T as IterScan>::scan(&mut self.iter).expect("scan error"))
                .collect()
        }
        #[inline]
        pub fn iter<'b, T: IterScan>(&'b mut self) -> ScannerIter<'a, 'b, T> {
            ScannerIter {
                inner: self,
                _marker: std::marker::PhantomData,
            }
        }
    }
    macro_rules ! iter_scan_impls { ($ ($ t : ty) *) => { $ (impl IterScan for $ t { type Output = Self ; # [inline] fn scan <'a , I : Iterator < Item = &'a str >> (iter : & mut I) -> Option < Self > { iter . next () ?. parse ::<$ t > () . ok () } }) * } ; }
    iter_scan_impls ! (char u8 u16 u32 u64 usize i8 i16 i32 i64 isize f32 f64 u128 i128 String) ;
    macro_rules ! iter_scan_tuple_impl { ($ ($ T : ident) *) => { impl <$ ($ T : IterScan) ,*> IterScan for ($ ($ T ,) *) { type Output = ($ (<$ T as IterScan >:: Output ,) *) ; # [inline] fn scan <'a , It : Iterator < Item = &'a str >> (_iter : & mut It) -> Option < Self :: Output > { Some (($ (<$ T as IterScan >:: scan (_iter) ?,) *)) } } } ; }
    iter_scan_tuple_impl!();
    iter_scan_tuple_impl!(A);
    iter_scan_tuple_impl ! (A B) ;
    iter_scan_tuple_impl ! (A B C) ;
    iter_scan_tuple_impl ! (A B C D) ;
    iter_scan_tuple_impl ! (A B C D E) ;
    iter_scan_tuple_impl ! (A B C D E F) ;
    iter_scan_tuple_impl ! (A B C D E F G) ;
    iter_scan_tuple_impl ! (A B C D E F G H) ;
    iter_scan_tuple_impl ! (A B C D E F G H I) ;
    iter_scan_tuple_impl ! (A B C D E F G H I J) ;
    iter_scan_tuple_impl ! (A B C D E F G H I J K) ;
    pub struct ScannerIter<'a, 'b, T> {
        inner: &'b mut Scanner<'a>,
        _marker: std::marker::PhantomData<fn() -> T>,
    }
    impl<'a, 'b, T: IterScan> Iterator for ScannerIter<'a, 'b, T> {
        type Item = <T as IterScan>::Output;
        #[inline]
        fn next(&mut self) -> Option<Self::Item> {
            <T as IterScan>::scan(&mut self.inner.iter)
        }
    }
}
pub mod marker {
    use super::*;
    use std::{iter::FromIterator, marker::PhantomData};
    #[derive(Debug, Copy, Clone)]
    pub struct Usize1;
    impl IterScan for Usize1 {
        type Output = usize;
        #[inline]
        fn scan<'a, I: Iterator<Item = &'a str>>(iter: &mut I) -> Option<Self::Output> {
            Some(<usize as IterScan>::scan(iter)?.checked_sub(1)?)
        }
    }
    #[derive(Debug, Copy, Clone)]
    pub struct Chars;
    impl IterScan for Chars {
        type Output = Vec<char>;
        #[inline]
        fn scan<'a, I: Iterator<Item = &'a str>>(iter: &mut I) -> Option<Self::Output> {
            Some(iter.next()?.chars().collect())
        }
    }
    #[derive(Debug, Copy, Clone)]
    pub struct CharsWithBase(pub char);
    impl MarkedIterScan for CharsWithBase {
        type Output = Vec<usize>;
        #[inline]
        fn mscan<'a, I: Iterator<Item = &'a str>>(self, iter: &mut I) -> Option<Self::Output> {
            Some(
                iter.next()?
                    .chars()
                    .map(|c| (c as u8 - self.0 as u8) as usize)
                    .collect(),
            )
        }
    }
    #[derive(Debug, Copy, Clone)]
    pub struct Collect<T: IterScan, B: FromIterator<<T as IterScan>::Output>> {
        size: usize,
        _marker: PhantomData<fn() -> (T, B)>,
    }
    impl<T: IterScan, B: FromIterator<<T as IterScan>::Output>> Collect<T, B> {
        pub fn new(size: usize) -> Self {
            Self {
                size,
                _marker: PhantomData,
            }
        }
    }
    impl<T: IterScan, B: FromIterator<<T as IterScan>::Output>> MarkedIterScan for Collect<T, B> {
        type Output = B;
        #[inline]
        fn mscan<'a, I: Iterator<Item = &'a str>>(self, iter: &mut I) -> Option<Self::Output> {
            Some(
                (0..self.size)
                    .map(|_| <T as IterScan>::scan(iter).expect("scan error"))
                    .collect::<B>(),
            )
        }
    }
}
/// return: [(start, length)]
pub fn run_length_encoding<T: PartialEq>(v: &[T]) -> Vec<(usize, usize)> {
    let mut res = Vec::new();
    for (i, a) in v.iter().enumerate() {
        if let Some((start, len)) = res.last_mut() {
            if &v[*start] == a {
                *len += 1;
                continue;
            }
        }
        res.push((i, 1));
    }
    res
}
fn main() {
    #![allow(unused_imports, unused_macros)]
    use std::io::{stdin, stdout, BufWriter, Read as _, Write as _};
    let mut _in_buf = Vec::new();
    stdin().read_to_end(&mut _in_buf).expect("io error");
    let _in_buf = unsafe { String::from_utf8_unchecked(_in_buf) };
    let mut scanner = Scanner::new(&_in_buf);
    macro_rules ! scan { () => { scan ! (usize) } ; (($ ($ t : tt) ,*)) => { ($ (scan ! ($ t)) ,*) } ; ([$ t : tt ; $ len : expr]) => { (0 ..$ len) . map (| _ | scan ! ($ t)) . collect ::< Vec < _ >> () } ; ([$ t : ty ; $ len : expr]) => { scanner . scan_vec ::<$ t > ($ len) } ; ([$ t : ty]) => { scanner . iter ::<$ t > () } ; ({ $ e : expr }) => { scanner . mscan ($ e) } ; ($ t : ty) => { scanner . scan ::<$ t > () } ; }
    let _out = stdout();
    let mut _out = BufWriter::new(_out.lock());
    macro_rules ! print { ($ ($ arg : tt) *) => (:: std :: write ! (_out , $ ($ arg) *) . expect ("io error")) }
    macro_rules ! println { ($ ($ arg : tt) *) => (:: std :: writeln ! (_out , $ ($ arg) *) . expect ("io error")) }
    macro_rules! echo {
        ($ iter : expr) => {
            echo!($iter, '\n')
        };
        ($ iter : expr , $ sep : expr) => {
            let mut iter = $iter.into_iter();
            if let Some(item) = iter.next() {
                print!("{}", item);
            }
            for item in iter {
                print!("{}{}", $sep, item);
            }
            println!();
        };
    }
    let n = scan!();
    let s = scan!({ marker::CharsWithBase('0') });
    let mut ans = 0;
    let mut acc = 0;
    let mut dp = vec![0; n];
    let run = run_length_encoding(&s);
    for (l, k) in run.iter().cloned() {
        if s[l] == 1 {
            for i in 0..k {
                acc += l + i + 1 - dp[i];
                ans += acc;
                dp[i] = l + k - i;
            }
        } else {
            ans += k * acc;
        }
    }
    println!("{}", ans);
}


import sys
input = sys.stdin.readline

def prog():
    ans = 0
    curr_total = 0
    last_loc_with_val = [-1]*500001
    n = int(input())
    s = input().strip()

    i = 0
    while i < n:
        if s[i] == '0':
            ans += curr_total
        else:
            l = i
            r = i
            while r + 1 < n and s[r+1] == '1':
                r += 1

            for length in range(1,r-l+2):
                curr_total += l + length - 1 - last_loc_with_val[length]
                ans += curr_total
                last_loc_with_val[length] = r - length + 1

            i = r

        i += 1

    print(ans)

prog()


#include<bits/stdc++.h>
using namespace std;

int N, M, K[105], J, flat[105], bs[105], ans, sum;
bool val = 1;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> N >> M;

	for (int i=1; i<=M; i++) {
		cin >> K[i] >> J;
		flat[K[i]] = J;
	}
	if (M == 0) {
		cout << 1 << '\n';
		return 0;
	}
	else {

		for (int i=1; i<=100; i++) {
			memset (bs, 0, sizeof(bs));

			ans = 0;
			int t = 1;
			int s = 1;
			for (int j=1; j<=100; j++) {
				if (j == t + i) {
					s++;
					t += i;
				}
				bs[j] = s;
			}
			for (int j=1; j<=M; j++) {
				if (bs[K[j]] == flat[K[j]]) ans++;
				if (ans == M) {
					if (sum == 0) sum = bs[N];
					else if (sum != bs[N]) {
						val = 0;
					}
				}
			}
		}
		if (val) cout << sum << '\n';
		else cout << -1 << '\n';
	}
}


#include<bits/stdc++.h>
using namespace std;

int N, M, K[105], J, flat[105], bs[105], ans, sum;
bool val = 1;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> N >> M;

	for (int i=1; i<=M; i++) {
		cin >> K[i] >> J;
		flat[K[i]] = J;
	}
	for (int i=1; i<=100; i++) {
		memset (bs, 0, sizeof(bs));

		ans = 0;
		int t = 1;
		int s = 1;
		for (int j=1; j<=100; j++) {
			if (j == t + i) {
				s++;
				t += i;
			}
			bs[j] = s;
		}
		for (int j=1; j<=M; j++) {
			if (bs[K[j]] == flat[K[j]]) ans++;
			if (ans == M) {
				if (sum == 0) sum = bs[N];
				else if (sum != bs[N]) {
					val = 0;
				}
			}
		}
	}
	if (val) cout << sum << '\n';
	else cout << -1 << '\n';
}


#include <bits/stdc++.h>

using namespace std;

int n, m, cnt;

vector < int > k, f;

int check(int x) {
    for (int i = 0; i < m; ++i) {
        if ((k[i] / x) + (k[i] % x > 0) != f[i])
            return 0;
    }
    return 1;
}

int main() {
    cin >> n >> m;
    k.resize(m);
    f.resize(m);
    for (int i = 0; i < m; ++i) {
        cin >> k[i] >> f[i];
    }
    for (int ans = 1; ans <= 100; ++ans) {
        if (!cnt && check(ans))
            cnt = ans;
        else if (cnt && check(ans)) {
            cout << -1;
            return 0;
        }

    }
    if (!cnt) {
        cout << -1;
    }
    else {
        cout << n / cnt + ((n % cnt) > 0);
    }
}


#include <bits/stdc++.h>

using namespace std;

int n, m, cnt;

vector < int > k, f;

int check(int x) {
    for (int i = 0; i < m; ++i) {
        if ((k[i] / x) + (k[i] % x > 0) != f[i])
            return 0;
    }
    return 1;
}

int x(int a, int b) {
    return a / b + ((a % b) > 0);
}

int main() {
    cin >> n >> m;
    k.resize(m);
    f.resize(m);
    for (int i = 0; i < m; ++i) {
        cin >> k[i] >> f[i];
    }
    for (int ans = 1; ans <= 100; ++ans) {
        if (!cnt && check(ans))
            cnt = ans;
        if (cnt && check(ans) && x(n, ans) != x(n, cnt)) {
            cout << -1;
            return 0;
        }

    }
    if (!cnt) {
        cout << -1;
    }
    else {
        cout << x(n, cnt);
    }
}


#include <bits/stdc++.h>

using namespace std;

int n, m, cnt;

vector < int > k, f;

int check(int x) {
    for (int i = 0; i < m; ++i) {
        if ((k[i] + (x - 1)) / x != f[i])
            return 0;
    }
    return 1;
}

int main() {
    cin >> n >> m;
    k.resize(m);
    f.resize(m);
    for (int i = 0; i < m; ++i) {
        cin >> k[i] >> f[i];
    }
    for (int ans = 1; ans <= 100; ++ans) {
        if (!cnt && check(ans))
            cnt = ans;
        else if (cnt && check(ans)) {
            cout << -1;
            return 0;
        }
    }
    if (!cnt) {
        cout << -1;
    }
    else {
        cout << (n) / cnt;
    }
}


#include <bits/stdc++.h>

using namespace std;

int n, m, cnt;

vector < int > k, f;

int check(int x) {
    for (int i = 0; i < m; ++i) {
        if ((k[i] + (x - 1)) / x != f[i])
            return 0;
    }
    return 1;
}

int main() {
    cin >> n >> m;
    k.resize(m);
    f.resize(m);
    for (int i = 0; i < m; ++i) {
        cin >> k[i] >> f[i];
    }
    for (int ans = 1; ans <= 100; ++ans) {
        if (!cnt && check(ans))
            cnt = ans;

    }
    if (!cnt) {
        cout << -1;
    }
    else {
        cout << (n + (cnt - 1)) / cnt;
    }
}


#include <bits/stdc++.h>

using namespace std;

int n, m, cnt;

vector < int > k, f;

int check(int x) {
    for (int i = 0; i < m; ++i) {
        if ((k[i] + (x - 1)) / x != f[i])
            return 0;
    }
    return 1;
}

int main() {
    cin >> n >> m;
    k.resize(m);
    f.resize(m);
    for (int i = 0; i < m; ++i) {
        cin >> k[i] >> f[i];
    }
    for (int ans = 1; ans <= 100; ++ans) {
        if (!cnt && check(ans))
            cnt = ans;
        else if (cnt && check(ans)) {
            cout << -1;
            return 0;
        }

    }
    cout << (n + (cnt - 1)) / cnt;

}


#include <bits/stdc++.h>

using namespace std;

int n, m, cnt;

vector < int > k, f;

int check(int x) {
    for (int i = 0; i < m; ++i) {
        if ((k[i] + (x - 1)) / x != f[i])
            return 0;
    }
    return 1;
}

int main() {
    cin >> n >> m;
    k.resize(m);
    f.resize(m);
    for (int i = 0; i < m; ++i) {
        cin >> k[i] >> f[i];
    }
    for (int ans = 1; ans <= 100; ++ans) {
        if (!cnt && check(ans))
            cnt = ans;

    }
    if (!cnt) {
        cout << -1;
    }
    else {
        cout << (n) / cnt;
    }
}


#include <bits/stdc++.h>

using namespace std;

int n, m, cnt;

vector < int > k, f;

int check(int x) {
    for (int i = 0; i < m; ++i) {
        if ((k[i] + (x - 1)) / x != f[i])
            return 0;
    }
    return 1;
}

int main() {
    cin >> n >> m;
    k.resize(m);
    f.resize(m);
    for (int i = 0; i < m; ++i) {
        cin >> k[i] >> f[i];
    }
    for (int ans = 1; ans <= 100; ++ans) {
        if (!cnt && check(ans))
            cnt = ans;
        else if (cnt && check(ans)) {
            cout << -1;
            return 0;
        }
    }
    if (!cnt) {
        cout << -1;
    }
    else {
        cout << (n + (cnt - 1)) / cnt;
    }
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;

	vector<int> k(m);
	vector<int> f(m);
	for (int i = 0; i < m; i++)
		cin >> k[i] >> f[i];

	int cnt = 0, ans;
	for (int i = 1; i <= 100; i++) {
		int j;
		for (j = 0; j < m && k[j] / i + (int)(k[j] % i != 0) == f[j]; j++);

		if (j == m)
			cnt++, ans = i;
	}

	if (cnt == 1)
		cout << n / ans + (n % ans != 0);
	else
		cout << -1;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;

	vector<int> k(m);
	vector<int> f(m);
	for (int i = 0; i < m; i++)
		cin >> k[i] >> f[i];

	int cnt = 0, ans;
	for (int i = 1; i < 1000; i++) {
		int j;
		for (j = 0; j < m && k[j] / i + (k[j] % i != 0) == f[j]; j++);

		if (j == m)
			cnt++, ans = i;
	}

	if (n == 1) {
		cout << 1;
		return 0;
	}

	for (int i = 0; i < m; i++) {
		if (n == k[i]) {
			cout << f[i];

			return 0;
		}
	}

	if (cnt == 1)
		cout << n / ans + (n % ans != 0);
	else
		cout << -1;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;

	vector<pair<int, int>> a(m + 1);

	for (int i = 0; i < m; i++)
		cin >> a[i].first >> a[i].second;

	a[m].first = a[m].second = 1;
	m++;

	int cnt = 0, ans = 0;
	for (int i = 1; i < 1000; i++) { //количество квартир на этаже
		int j;
		for (j = 0; j < m && a[j].first / i + (a[j].first % i != 0) == a[j].second; j++);

		if (j == m)
			if (ans != n / i + (n % i != 0))
				cnt++, ans = n / i + (n % i != 0);
	}

	for (int i = 0; i < m; i++)
		if (n == a[i].first) {
			cout << a[i].second;
			return 0;
		}

	if (cnt == 1)
		cout << ans;
	else
		cout << -1;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;

	vector<int> k(m + 1);
	vector<int> f(m + 1);
	for (int i = 0; i < m; i++)
		cin >> k[i] >> f[i];

	k[m] = f[m] = 1;
	m++;

	int cnt = 0, ans;
	for (int i = 1; i < 1000; i++) { //количество квартир на этаже
		int j;
		for (j = 0; j < m && k[j] / i + (k[j] % i != 0) == f[j]; j++);

		if (j == m)
			cnt++, ans = i;
	}

	for (int i = 0; i < m; i++)
		if (n == k[i]) {
			cout << f[i];
			return 0;
		}

	if (cnt == 1)
		cout << n / ans + (n % ans != 0);
	else
		cout << -1;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;

	vector<int> k(m);
	vector<int> f(m);
	for (int i = 0; i < m; i++)
		cin >> k[i] >> f[i];

	int cnt = 0, ans;
	for (int i = 1; i < 1000; i++) {
		int j;
		for (j = 0; j < m && k[j] / i + (k[j] % i != 0) == f[j]; j++);

		if (j == m)
			cnt++, ans = i;
	}

	if (n == 1) {
		cout << 1;
		return 0;
	}

	for (int i = 0; i < m; i++) {
		if (n == k[i])
			cout << f[i];

		return 0;
	}

	if (cnt == 1)
		cout << n / ans + (n % ans != 0);
	else
		cout << -1;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;

	vector<pair<int, int>> a(m + 1);

	for (int i = 0; i < m; i++)
		cin >> a[i].first >> a[i].second;

	a[m].first = a[m].second = 1;
	m++;

	sort(a.begin(), a.end());

	int cnt = 0, ans;
	for (int i = 1; i < 1000; i++) { //количество квартир на этаже
		int j;
		for (j = 0; j < m && a[j].first / i + (a[j].first % i != 0) == a[j].second; j++);

		if (j == m)
			cnt++, ans = i;
	}

	for (int i = 0; i < m - 1; i++)
		if (a[i].second == a[i + 1].second && a[i].first <= n && n <= a[i + 1].first) {
			cout << a[i].second;
			return 0;
		}

	for (int i = 0; i < m; i++)
		if (n == a[i].first) {
			cout << a[i].second;
			return 0;
		}

	if (cnt == 1)
		cout << n / ans + (n % ans != 0);
	else
		cout << -1;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ull> vull;
typedef vector <vll> vvll;
typedef long double ld;
typedef vector <ld> vld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef vector <vpii> vvpii;
typedef vector <bool> vbool;

#define forn(i, x, y) for (ll i = x; i < y; ++i)
#define rforn(i, x, y) for (ll i = x; i >= y; --i)
#define vec vector
#define mp make_pair
#define add push_back
#define del pop_back
#define addf push_front
#define delf pop_front
#define int ll
#define ins insert
#define ers erase
#define F first
#define S second
#define sqr(x) ((x) * (x))
#define pw(x) (1LL << (x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rev(x) reverse(all(x))
#define sz(x) (ll)(x).size()
#define rsz(x) resize(x)
#define cpy(x, T, c) copy(all(x), ostream_iterator <T>(cout, c))
#define mem(x, val) memset(x, val, sizeof(x))
#define endl "\n"

const ll INF = 1e9 + 2017;
const ll MOD = ll(1e9) + 7;
const ld EPS = 1e-10;
const ld PI = acos(-1.0);

const int MAXN = 1e6 + 10;
int k[MAXN], f[MAXN];

void source()
{
	int n, m;
	cin >> n >> m;
	if (n == 1)
	{
		cout << 1;
		return;
	}
	forn(i, 0, m)
	{
		cin >> k[i] >> f[i];
	}
	vi res;
	forn(i, 1, MAXN + 1)
	{
		bool t = 1;
		forn(j, 0, m)
		{
			if (!((f[j] - 1) * i < k[j] && k[j] <= f[j] * i))
			{
				t = 0;
			}
		}
		if (t)
		{
			res.add(i);
		}
	}
	if (sz(res) > 1)
	{
		cout << -1;
	}
	else
	{
		cout << (n - 1) / res[0] + 1;
	}
}

int32_t main()
{
	srand(time(0));
	ios::sync_with_stdio(0);
#ifdef _F1A4X_
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	source();
#ifdef _F1A4X_
	cerr << endl << endl << "\t" << clock() << " ms" << endl;
#endif
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ull> vull;
typedef vector <vll> vvll;
typedef long double ld;
typedef vector <ld> vld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef vector <vpii> vvpii;
typedef vector <bool> vbool;

#define forn(i, x, y) for (ll i = x; i < y; ++i)
#define rforn(i, x, y) for (ll i = x; i >= y; --i)
#define vec vector
#define mp make_pair
#define add push_back
#define del pop_back
#define addf push_front
#define delf pop_front
#define int ll
#define ins insert
#define ers erase
#define F first
#define S second
#define sqr(x) ((x) * (x))
#define pw(x) (1LL << (x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rev(x) reverse(all(x))
#define sz(x) (ll)(x).size()
#define rsz(x) resize(x)
#define cpy(x, T, c) copy(all(x), ostream_iterator <T>(cout, c))
#define mem(x, val) memset(x, val, sizeof(x))
#define endl "\n"

const ll INF = 1e9 + 2017;
const ll MOD = ll(1e9) + 7;
const ld EPS = 1e-10;
const ld PI = acos(-1.0);

const int MAXN = 100;
int k[MAXN], f[MAXN];

void source()
{
	int n, m;
	cin >> n >> m;
	forn(i, 0, m)
	{
		cin >> k[i] >> f[i];
	}
	vi res;
	forn(i, 1, MAXN + 1)
	{
		bool t = 1;
		forn(j, 0, m)
		{
			if (!((f[j] - 1) * i < k[j] && k[j] <= f[j] * i))
			{
				t = 0;
			}
		}
		if (t)
		{
			res.add(i);
		}
	}
	if (sz(res) > 1)
	{
		cout << -1;
	}
	else
	{
		cout << (n - 1) / res[0] + 1;
	}
}

int32_t main()
{
	srand(time(0));
	ios::sync_with_stdio(0);
#ifdef _F1A4X_
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	source();
#ifdef _F1A4X_
	cerr << endl << endl << "\t" << clock() << " ms" << endl;
#endif
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ull> vull;
typedef vector <vll> vvll;
typedef long double ld;
typedef vector <ld> vld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef vector <vpii> vvpii;
typedef vector <bool> vbool;

#define forn(i, x, y) for (ll i = x; i < y; ++i)
#define rforn(i, x, y) for (ll i = x; i >= y; --i)
#define vec vector
#define mp make_pair
#define add push_back
#define del pop_back
#define addf push_front
#define delf pop_front
#define int ll
#define ins insert
#define ers erase
#define F first
#define S second
#define sqr(x) ((x) * (x))
#define pw(x) (1LL << (x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rev(x) reverse(all(x))
#define sz(x) (ll)(x).size()
#define rsz(x) resize(x)
#define cpy(x, T, c) copy(all(x), ostream_iterator <T>(cout, c))
#define mem(x, val) memset(x, val, sizeof(x))
#define endl "\n"

const ll INF = 1e9 + 2017;
const ll MOD = ll(1e9) + 7;
const ld EPS = 1e-10;
const ld PI = acos(-1.0);

const int MAXN = 100;
int k[MAXN], f[MAXN];

void source()
{
	int n, m;
	cin >> n >> m;
	if (n == 1)
	{
		cout << 1;
		return;
	}
	forn(i, 0, m)
	{
		cin >> k[i] >> f[i];
	}
	vi res;
	forn(i, 1, MAXN + 1)
	{
		bool t = 1;
		forn(j, 0, m)
		{
			if (!((f[j] - 1) * i < k[j] && k[j] <= f[j] * i))
			{
				t = 0;
			}
		}
		if (t)
		{
			res.add(i);
		}
	}
	if (sz(res) > 1)
	{
		cout << -1;
	}
	else
	{
		cout << (n - 1) / res[0] + 1;
	}
}

int32_t main()
{
	srand(time(0));
	ios::sync_with_stdio(0);
#ifdef _F1A4X_
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	source();
#ifdef _F1A4X_
	cerr << endl << endl << "\t" << clock() << " ms" << endl;
#endif
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ull> vull;
typedef vector <vll> vvll;
typedef long double ld;
typedef vector <ld> vld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef vector <vpii> vvpii;
typedef vector <bool> vbool;

#define forn(i, x, y) for (ll i = x; i < y; ++i)
#define rforn(i, x, y) for (ll i = x; i >= y; --i)
#define vec vector
#define mp make_pair
#define add push_back
#define del pop_back
#define addf push_front
#define delf pop_front
#define int ll
#define ins insert
#define ers erase
#define F first
#define S second
#define sqr(x) ((x) * (x))
#define pw(x) (1LL << (x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rev(x) reverse(all(x))
#define sz(x) (ll)(x).size()
#define rsz(x) resize(x)
#define cpy(x, T, c) copy(all(x), ostream_iterator <T>(cout, c))
#define mem(x, val) memset(x, val, sizeof(x))
#define endl "\n"

const ll INF = 1e9 + 2017;
const ll MOD = ll(1e9) + 7;
const ld EPS = 1e-10;
const ld PI = acos(-1.0);

const int MAXN = 1010;
int arr[MAXN];

void source()
{
	int n, m;
	cin >> n >> m;
	int k, f;
	forn(j, 0, m)
	{
		cin >> k >> f;
		if (k == n)
		{
			cout << f;
			return;
		}
		forn(i, 1, MAXN)
		{
			if ((f - 1) * i < k && f * i >= k)
			{
				arr[i]++;
			}
		}
	}
	int cnt = 0;
	forn(i, 1, MAXN)
	{
		if (arr[i] == m)
		{
			cnt++;
		}
	}
	if (cnt > 1)
	{
		cout << -1;
	}
	else
	{
		forn(i, 1, MAXN)
		{
			if (arr[i] == m)
			{
				cout << (n - 1) / i + 1;
				return;
			}
		}
	}
}

int32_t main()
{
	srand(time(0));
	ios::sync_with_stdio(0);
#ifdef _F1A4X_
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	source();
#ifdef _F1A4X_
	cerr << endl << endl << "\t" << clock() << " ms" << endl;
#endif
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ull> vull;
typedef vector <vll> vvll;
typedef long double ld;
typedef vector <ld> vld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef vector <vpii> vvpii;
typedef vector <bool> vbool;

#define forn(i, x, y) for (ll i = x; i < y; ++i)
#define rforn(i, x, y) for (ll i = x; i >= y; --i)
#define vec vector
#define mp make_pair
#define add push_back
#define del pop_back
#define addf push_front
#define delf pop_front
#define int ll
#define ins insert
#define ers erase
#define F first
#define S second
#define sqr(x) ((x) * (x))
#define pw(x) (1LL << (x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rev(x) reverse(all(x))
#define sz(x) (ll)(x).size()
#define rsz(x) resize(x)
#define cpy(x, T, c) copy(all(x), ostream_iterator <T>(cout, c))
#define mem(x, val) memset(x, val, sizeof(x))
#define endl "\n"

const ll INF = 1e9 + 2017;
const ll MOD = ll(1e9) + 7;
const ld EPS = 1e-10;
const ld PI = acos(-1.0);

const int MAXN = 110;
int arr[MAXN];

void source()
{
	int n, m;
	cin >> n >> m;
	int k, f;
	forn(j, 0, m)
	{
		cin >> k >> f;
		forn(i, 1, MAXN)
		{
			int res = (f - 1) * i, res2 = f * i;
			if ((f - 1) * i < k && f * i >= k)
			{
				arr[i]++;
			}
		}
	}
	int cnt = 0;
	forn(i, 1, MAXN)
	{
		if (arr[i] == m)
		{
			cnt++;
		}
	}
	if (cnt > 1)
	{
		cout << -1;
	}
	else
	{
		forn(i, 1, MAXN)
		{
			if (arr[i] == m)
			{
				cout << (n - 1) / i + 1;
				return;
			}
		}
	}
}

int32_t main()
{
	srand(time(0));
	ios::sync_with_stdio(0);
#ifdef _F1A4X_
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	source();
#ifdef _F1A4X_
	cerr << endl << endl << "\t" << clock() << " ms" << endl;
#endif
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ull> vull;
typedef vector <vll> vvll;
typedef long double ld;
typedef vector <ld> vld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef vector <vpii> vvpii;
typedef vector <bool> vbool;

#define forn(i, x, y) for (ll i = x; i < y; ++i)
#define rforn(i, x, y) for (ll i = x; i >= y; --i)
#define vec vector
#define mp make_pair
#define add push_back
#define del pop_back
#define addf push_front
#define delf pop_front
#define int ll
#define ins insert
#define ers erase
#define F first
#define S second
#define sqr(x) ((x) * (x))
#define pw(x) (1LL << (x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rev(x) reverse(all(x))
#define sz(x) (ll)(x).size()
#define rsz(x) resize(x)
#define cpy(x, T, c) copy(all(x), ostream_iterator <T>(cout, c))
#define mem(x, val) memset(x, val, sizeof(x))
#define endl "\n"

const ll INF = 1e9 + 2017;
const ll MOD = ll(1e9) + 7;
const ld EPS = 1e-10;
const ld PI = acos(-1.0);

const int MAXN = 1e6 + 10;
int k[MAXN], f[MAXN];

void source()
{
	int n, m;
	cin >> n >> m;
	if (n == 1)
	{
		cout << 1;
		return;
	}
	forn(i, 0, m)
	{
		cin >> k[i] >> f[i];
		if (k[i] == n)
		{
			cout << f[i];
			return;
		}
	}
	vi res;
	forn(i, 1, MAXN + 1)
	{
		bool t = 1;
		forn(j, 0, m)
		{
			if (!((f[j] - 1) * i < k[j] && k[j] <= f[j] * i))
			{
				t = 0;
			}
		}
		if (t)
		{
			res.add(i);
		}
	}
	if (sz(res) > 1)
	{
		cout << -1;
	}
	else
	{
		cout << (n - 1) / res[0] + 1;
	}
}

int32_t main()
{
	srand(time(0));
	ios::sync_with_stdio(0);
#ifdef _F1A4X_
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	source();
#ifdef _F1A4X_
	cerr << endl << endl << "\t" << clock() << " ms" << endl;
#endif
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ull> vull;
typedef vector <vll> vvll;
typedef long double ld;
typedef vector <ld> vld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef vector <vpii> vvpii;
typedef vector <bool> vbool;

#define forn(i, x, y) for (int i = x; i < y; ++i)
#define rforn(i, x, y) for (int i = x; i >= y; --i)
#define vec vector
#define mp make_pair
#define add push_back
#define del pop_back
#define addf push_front
#define delf pop_front
#define ins insert
#define ers erase
#define F first
#define S second
#define sqr(x) ((x) * (x))
#define pw(x) (1LL << (x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rev(x) reverse(all(x))
#define sz(x) (ll)(x).size()
#define rsz(x) resize(x)
#define cpy(x, T, c) copy(all(x), ostream_iterator <T>(cout, c))
#define mem(x, val) memset(x, val, sizeof(x))

const ll INF = 1e9 + 2017;
const ll MOD = ll(1e9) + 7;
const ld EPS = 1e-10;
const ld PI = acos(-1.0);

const int MAXN = 1e6 + 10;
int k[MAXN], f[MAXN];

void source()
{
	int n, m;
	cin >> n >> m;
	if (n == 1)
	{
		cout << 1;
		return;
	}
	forn(i, 0, m)
	{
		cin >> k[i] >> f[i];
		if (k[i] == n)
		{
			cout << f[i];
			return;
		}
	}
	vi res;
	forn(i, 1, MAXN + 1)
	{
		bool t = 1;
		forn(j, 0, m)
		{
			if (!((f[j] - 1) * i < k[j] && k[j] <= f[j] * i))
			{
				t = 0;
			}
		}
		if (t)
		{
			res.add(i);
		}
	}
	set <int> st;
	forn(i, 0, sz(res))
	{
		st.insert((n - 1) / res[i] + 1);
	}
	if (sz(st) > 1)
	{
		cout << -1;
	}
	else
	{
		cout << *st.begin();
	}
}

int main()
{
	srand(time(0));
	ios::sync_with_stdio(0);
#ifdef _F1A4X_
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	source();
#ifdef _F1A4X_
	cerr << endl << endl << "\t" << clock() << " ms" << endl;
#endif
}


#include <iostream>
#include <string>
#include <cstring>
#include <map>
#include <cmath>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <time.h>
#include <ctime>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <queue>

using namespace std;

int main() {
	int n, m, ka;
	ka = 0;
	int s = 0;
	int dat = 0;
	int kok = 1;
	cin >> n >> m;
	vector<int> vect(m);
	vector<int> ans(100);
	vector<int> re(100);
	vector<int> vect2(m);
	for (int i = 0; i < m; i++) {
		int k, f;
		cin >> k >> f;
		vect[i] = k;
		vect2[i] = f;
	}
	//cout << vect2[0] <<  vect2[1] << vect2[2] << endl;
	for (int z = 1; z <= 100; z++)
	{
		for (int i = 0; i < m; i++) {
			if (vect2[i] * z - vect[i] < z && vect2[i] * z - vect[i] >= 0) {
				s++;
			}
			if (s == m) {
				re[ka] = z;
				dat++;
				ka++;
			}
		}
		s = 0;
	}
	if (dat != 1) {
		for (int i = 0; i < dat; i++) {
			ans[i] = n / re[i];
			if (n % re[i] != 0) {
				ans[i]++;
			}
			if (i > 0) {
				if (ans[i] == ans[i - 1]) {
					kok++;
				}
			}
		}
		if (kok == dat) {
			cout << ans[0] << endl;
		}
		else {
			cout << "-1" << endl;
		}
	}
	else {
		int car;
		car = n / re[0];
		if (n % re[0] != 0) {
			car++;
		}
		cout << car << endl;
	}
	//system("pause");
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <map>
#include <cmath>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <time.h>
#include <ctime>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <queue>

using namespace std;

int main() {
	int n, m,re,ans;
	int s = 0;
	int dat = 0;
	cin >> n >> m;
	vector<int> vect(m);
	vector<int> vect2(m);
	for (int i = 0; i < m; i++) {
			int k, f;
			cin >> k >> f;
			vect[i] = k;
			vect2[i] = f;
		}
	//cout << vect2[0] <<  vect2[1] << vect2[2] << endl;
	for (int z = 1; z <= 100; z++)
	{
		for (int i = 0; i < m; i++) {
			if (vect2[i] * z - vect[i] <= z && vect2[i] * z - vect[i] >= 0) {
				s++;
			}
			if (s == m) {
				re = z;
				dat++;
			}
		}
		s = 0;
	}
	if (dat == 1) {
		ans = n / re;
		if (n % re != 0) {
			ans++;
		}
		cout << ans << endl;
	}
	else {
		cout << "-1" << endl;
	}
	//system("pause");
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <map>
#include <cmath>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <time.h>
#include <ctime>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <queue>

using namespace std;

int main() {
	int n, m,re,ans;
	int s = 0;
	int dat = 0;
	cin >> n >> m;
	vector<int> vect(m);
	vector<int> vect2(m);
	for (int i = 0; i < m; i++) {
			int k, f;
			cin >> k >> f;
			vect[i] = k;
			vect2[i] = f;
		}
	cout << vect2[0] <<  vect2[1] << vect2[2] << endl;
	for (int z = 1; z <= 100; z++)
	{
		for (int i = 0; i < m; i++) {
			if (vect2[i] * z - vect[i] <= z && vect2[i] * z - vect[i] >= 0) {
				s++;
			}
			if (s == m) {
				re = z;
				dat++;
			}
		}
		s = 0;
	}
	if (dat == 1) {
		ans = n / re;
		if (n % re == 0) {
			ans++;
		}
		cout << ans << endl;
	}
	else {
		cout << "-1" << endl;
	}
	system("pause");
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <map>
#include <cmath>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <time.h>
#include <ctime>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <queue>

using namespace std;

int main() {
	int n, m,re,ans;
	int s = 0;
	int dat = 0;
	cin >> n >> m;
	vector<int> vect(m);
	vector<int> vect2(m);
	for (int i = 0; i < m; i++) {
			int k, f;
			cin >> k >> f;
			vect[i] = k;
			vect2[i] = f;
		}
	//cout << vect2[0] <<  vect2[1] << vect2[2] << endl;
	for (int z = 1; z <= 100; z++)
	{
		for (int i = 0; i < m; i++) {
			if (vect2[i] * z - vect[i] <= z && vect2[i] * z - vect[i] >= 0) {
				s++;
			}
			if (s == m) {
				re = z;
				dat++;
			}
		}
		s = 0;
	}
	if (dat == 1) {
		ans = n / re;
		if (n % re == 0) {
			ans++;
		}
		cout << ans << endl;
	}
	else {
		cout << "-1" << endl;
	}
	//system("pause");
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <map>
#include <cmath>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <time.h>
#include <ctime>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <queue>

using namespace std;

int main() {
	int n, m, ka;
	ka = 0;
	int s = 0;
	int dat = 0;
	int kok = 1;
	cin >> n >> m;
	vector<int> vect(m);
	vector<int> ans(100);
	vector<int> re(100);
	vector<int> vect2(m);
	for (int i = 0; i < m; i++) {
		int k, f;
		cin >> k >> f;
		vect[i] = k;
		vect2[i] = f;
	}
	//cout << vect2[0] <<  vect2[1] << vect2[2] << endl;
	for (int z = 1; z <= 100; z++)
	{
		for (int i = 0; i < m; i++) {
			if (vect2[i] * z - vect[i] <= z && vect2[i] * z - vect[i] >= 0) {
				s++;
			}
			if (s == m) {
				re[ka] = z;
				dat++;
				ka++;
			}
		}
		s = 0;
	}
	if (dat != 1) {
		for (int i = 0; i < dat; i++) {
			ans[i] = n / re[i];
			if (n % re[i] != 0) {
				ans[i]++;
			}
			if (i > 0) {
				if (ans[i] == ans[i - 1]) {
					kok++;
				}
			}
		}
		if (kok == dat) {
			cout << ans[0] << endl;
		}
		else {
			cout << "-1" << endl;
		}
	}
	else {
		int car;
		car = n / re[0];
		if (n % re[0] != 0) {
			car++;
		}
		cout << car << endl;
	}
	//system("pause");
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <map>
#include <cmath>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <time.h>
#include <ctime>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <queue>

using namespace std;

int main() {
	int n, m, ka;
	ka = 0;
	int s = 0;
	int dat = 0;
	int kok = 1;
	cin >> n >> m;
	if (n == 1 && m == 0) {
		cout << "1" << endl;
	}
	else {
		vector<int> vect(m);
		vector<int> ans(100);
		vector<int> re(100);
		vector<int> vect2(m);
		for (int i = 0; i < m; i++) {
			int k, f;
			cin >> k >> f;
			vect[i] = k;
			vect2[i] = f;
		}
		//cout << vect2[0] <<  vect2[1] << vect2[2] << endl;
		for (int z = 1; z <= 100; z++)
		{
			for (int i = 0; i < m; i++) {
				if (vect2[i] * z - vect[i] < z && vect2[i] * z - vect[i] >= 0) {
					s++;
				}
				if (s == m) {
					re[ka] = z;
					dat++;
					ka++;
				}
			}
			s = 0;
		}
		if (dat != 1) {
			for (int i = 0; i < dat; i++) {
				ans[i] = n / re[i];
				if (n % re[i] != 0) {
					ans[i]++;
				}
				if (i > 0) {
					if (ans[i] == ans[i - 1]) {
						kok++;
					}
				}
			}
			if (kok == dat) {
				cout << ans[0] << endl;
			}
			else {
				cout << "-1" << endl;
			}
		}
		else {
			int car;
			car = n / re[0];
			if (n % re[0] != 0) {
				car++;
			}
			cout << car << endl;
		}
	}
	//system("pause");
	return 0;
}


#include <iostream>
#include <cmath>
using namespace std;

int main() {
    int n, m;
    int s, f;
    cin >> n >> m;
    if (m == 0) {
        if (n == 1) {
            cout << 1;
        } else {
            cout << -1;
        }
        return 0;
    }
    int mink, maxk;
    mink = 0;
    maxk = 100000;
    for (int i = 0; i < m; i++) {
        cin >> s >> f;
        s--; f--;
        if (f == 0) {
            mink = max(mink, s+1);
        } else {
            mink = max(mink, (int)floor(s/(f+1.))+1);
            maxk = min(maxk, (int)floor(s/(double)f));
        }
    }
    //cout << mink << " " << maxk << endl;
    int a = 1 + (n-1)/mink;
    int b = 1 + (n-1)/maxk;
    if (a == b) cout << a;
    else cout << -1;
    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;

int main() {
    int n, m;
    int s, f;
    cin >> n >> m;
    if (m == 0) {
        cout << -1;
        return 0;
    }
    int mink, maxk;
    mink = 0;
    maxk = 100000;
    for (int i = 0; i < m; i++) {
        cin >> s >> f;
        s--; f--;
        if (f == 0) {
            mink = max(mink, s+1);
        } else {
            mink = max(mink, (int)floor(s/(f+1.))+1);
            maxk = min(maxk, (int)floor(s/(double)f));
        }
    }
    //cout << mink << " " << maxk << endl;
    int a = 1 + (n-1)/mink;
    int b = 1 + (n-1)/maxk;
    if (a == b) cout << a;
    else cout << -1;
    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;

int main() {
    int n, m;
    int s, f;
    cin >> n >> m;
    int mink, maxk;
    mink = 0;
    maxk = 100000;
    for (int i = 0; i < m; i++) {
        cin >> s >> f;
        s--; f--;
        if (f == 0) {
            mink = max(mink, s+1);
        } else {
            mink = max(mink, (int)floor(s/(f+1.))+1);
            maxk = min(maxk, (int)floor(s/(double)f));
        }
    }
    cout << mink << ' ' << maxk << endl;
    int a = 1 + (n-1)/mink;
    int b = 1 + (n-1)/maxk;
    if (a == b) cout << a;
    else cout << -1;
    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;

int main() {
    int n, m;
    int s, f;
    cin >> n >> m;
    int mink, maxk;
    mink = 0;
    maxk = 100000;
    for (int i = 0; i < m; i++) {
        cin >> s >> f;
        s--; f--;
        if (f == 0) {
            mink = max(mink, s+1);
        } else {
            mink = max(mink, (int)floor(s/(f+1.))+1);
            maxk = min(maxk, (int)floor(s/(double)f));
        }
    }
    int a = 1 + (n-1)/mink;
    int b = 1 + (n-1)/maxk;
    if (a == b) cout << a;
    else cout << -1;
    return 0;
}


#include <iostream>
#include <cmath>
using namespace std;

int main() {
    int n, m;
    int s, f;
    cin >> n >> m;
    int mink, maxk;
    mink = 0;
    maxk = 100000;
    for (int i = 0; i < m; i++) {
        cin >> s >> f;
        s--; f--;
        if (f == 0) {
            mink = max(mink, s+1);
        } else {
            mink = max(mink, (int)floor(s/(f+1.))+1);
            maxk = min(maxk, (int)ceil(s/(double)f));
        }
    }
    int a = 1 + (n-1)/mink;
    int b = 1 + (n-1)/maxk;
    if (a == b) cout << a;
    else cout << -1;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[101],b[101],q[101];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m,cnt=0,d=0;
	cin>>n>>m;
	if(!m){
		cout<<-1;
		return 0;
	}
	int mx=0;
	for(int i=1;i<=m;i++){
		cin>>a[i]>>b[i];
		if(a[i]==n){
			cout<<b[i];
			return 0;
		}
		q[b[i]]++;
		mx=max(q[b[i]],mx);
	}
	for(int i=mx;i<=100;i++){
		bool w=0;
		for(int j=1;j<=m;j++){
			if((a[j]+i-1)/i!=b[j]){
				w=1;
			}
		}
		if(!w){
			cnt++;
			d=i;
		//	cout<<i<<" ";
		}
	}
	if(cnt!=1){
		cout<<-1;
		return 0;
	}
	cout<<(n+d-1)/d;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[1001],b[1001],q[101][101];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m,cnt=0,q=0;
	cin>>n>>m;
	if(!m){
		cout<<-1;
		return 0;
	}
	for(int i=1;i<=m;i++){
		cin>>a[i]>>b[i];
	}
	for(int i=1;i<=100;i++){
		bool w=0;
		for(int j=1;j<=m;j++){
			if((a[j]+i-1)/i!=b[j]){
				w=1;
				break;
			}
		}
		if(!w){
			cnt++;
			q=i;
		}
	}
	if(cnt==1){
		cout<<(n+q-1)/q;
		return 0;
	}
	cout<<-1;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[1001],b[1001],q[101][101];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m,cnt=0,q=0;
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>a[i]>>b[i];
	}
	for(int i=1;i<=100;i++){
		bool w=0;
		for(int j=1;j<=m;j++){
			if((a[j]+i-1)/i!=b[j]){
				w=1;
				break;
			}
		}
		if(!w){
			cnt++;
			q=i;
		}
	}
	if(cnt==1){
		cout<<(n+q-1)/q;
		return 0;
	}
	cout<<-1;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[101],b[101],q[101];
set<int>s;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m,cnt=0,d=0;
	cin>>n>>m;
	if(!m){
		cout<<-1;
		return 0;
	}
	int mx=0;
	for(int i=1;i<=m;i++){
		cin>>a[i]>>b[i];
		if(a[i]==n){
			cout<<b[i];
			return 0;
		}
		q[b[i]]++;
		mx=max(q[b[i]],mx);
	}
	for(int i=mx;i<=100;i++){
		bool w=0;
		for(int j=1;j<=m;j++){
			if((a[j]+i-1)/i!=b[j]){
				w=1;
			}
		}
		if(!w){
			d=i;
			s.insert((n+d-1)/d);
		}
	}
	if(s.size()!=1){
		cout<<-1;
		return 0;
	}
	cout<<(n+d-1)/d;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[101],b[101],q[101];
set<int>s;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m,cnt=0,d=0;
	cin>>n>>m;
	if(n==1){
		cout<<1;
		return 0;
	}
	if(!m){
		cout<<-1;
		return 0;
	}
	int mx=0;
	for(int i=1;i<=m;i++){
		cin>>a[i]>>b[i];
		if(a[i]==n){
			cout<<b[i];
			return 0;
		}
		q[b[i]]++;
		mx=max(q[b[i]],mx);
	}
	for(int i=mx;i<=100;i++){
		bool w=0;
		for(int j=1;j<=m;j++){
			if((a[j]+i-1)/i!=b[j]){
				w=1;
			}
		}
		if(!w){
			d=i;
			s.insert((n+d-1)/d);
		}
	}
	if(s.size()!=1){
		cout<<-1;
		return 0;
	}
	cout<<(n+d-1)/d;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int a[101],b[101],q[101];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,m,cnt=0,d=0;
	cin>>n>>m;
	if(!m){
		cout<<-1;
		return 0;
	}
	int mx=0;
	for(int i=1;i<=m;i++){
		cin>>a[i]>>b[i];
		q[b[i]]++;
		mx=max(q[b[i]],mx);
	}
	for(int i=mx;i<=100;i++){
		bool w=0;
		for(int j=1;j<=m;j++){
			if((a[j]+i-1)/i!=b[j]){
				w=1;
			}
		}
		if(!w){
			cnt++;
			d=i;
		//	cout<<i<<" ";
		}
	}
	if(cnt!=1){
		cout<<-1;
		return 0;
	}
	cout<<(n+d-1)/d;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define ll long long
#define ld long double
#define al 0x3F3F3F3F
#define ull unsigned long long
#define PI pair < int, int >
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
#define resize(v) v.resize(unique(all(v)) - v.begin());
#define int ll

const int mod = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 123;
const int N = 1e6 + 123;
const int INF = al;
const ll INFL = 3e18 + 1;
const double pi = acos(-1.0);
const double eps = 1e-9;

int n, m, a[101], b[101], cnt = INF;
set <int> s;

inline int gcd(int a, int b) {
	if (!b) return a;
	gcd(b, a % b);
}

inline void boost() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
}

inline void Solve() {
    boost();
    cin >> n >> m;
    for (int i = 1; i <= m; i++) cin >> a[i] >> b[i];
    for (int i = 1; i <= m; i++) {
    	for (int j = 1; j <= m; j++) {
    		if (i == j) continue;
    		if (abs(a[i] - a[j]) == abs(b[i] - b[j]) && abs(b[i] - b[j]) == 1) {
    			int cur = min(a[i], a[j]), cur2 = min(b[i], b[j]);
    			if (cur % cur2 != 0) continue;
    			cnt = cur / cur2;
    			s.in(cnt);
    		}
    	}
    }
    if (cnt == INF || sz(s) != 1) cout << -1, exit(0);
    cout << n / cnt + (n % cnt != 0);
}

main () {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	int IZIPROBLEM = -1, pro100 = 1, tt = 1;
	while (tt--) {
		Solve();
		exit(pro100 + IZIPROBLEM);
	}
}


#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define ll long long
#define ld long double
#define al 0x3F3F3F3F
#define ull unsigned long long
#define PI pair < int, int >
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
#define resize(v) v.resize(unique(all(v)) - v.begin());
#define int ll

const int mod = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 123;
const int N = 1e6 + 123;
const int INF = al;
const ll INFL = 3e18 + 1;
const double pi = acos(-1.0);
const double eps = 1e-9;

int n, m, a[101], b[101], cnt = INF;
set <int> s;

inline int gcd(int a, int b) {
	if (!b) return a;
	gcd(b, a % b);
}

inline void boost() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
}

inline void Solve() {
    boost();
    cin >> n >> m;
    for (int i = 1; i <= m; i++) cin >> a[i] >> b[i];
    for (int i = 1; i <= m; i++) {
    	for (int j = 1; j <= m; j++) {
    		if (i == j) continue;
    		if (abs(a[i] - a[j]) == abs(b[i] - b[j]) && abs(b[i] - b[j]) == 1) {
    			int cur = min(a[i], a[j]), cur2 = min(b[i], b[j]);
    			if (cur % cur2 != 0) continue;
    			cnt = cur / cur2;
    		}
    	}
    }
    if (cnt == INF) cout << -1, exit(0);
    cout << n / cnt + (n % cnt != 0);
}

main () {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	int IZIPROBLEM = -1, pro100 = 1, tt = 1;
	while (tt--) {
		Solve();
		exit(pro100 + IZIPROBLEM);
	}
}


#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define ll long long
#define ld long double
#define al 0x3F3F3F3F
#define ull unsigned long long
#define PI pair < int, int >
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
#define resize(v) v.resize(unique(all(v)) - v.begin());
#define int ll

const int mod = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 123;
const int N = 1e6 + 123;
const int INF = al;
const ll INFL = 3e18 + 1;
const double pi = acos(-1.0);
const double eps = 1e-9;

int n, m, a[101], b[101], cnt = INF;
set <int> s;

inline int gcd(int a, int b) {
	if (!b) return a;
	gcd(b, a % b);
}

inline void boost() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
}

inline void Solve() {
    boost();
    cin >> n >> m;
    for (int i = 1; i <= m; i++) cin >> a[i] >> b[i];
    for (int i = 1; i <= m; i++) {
    	for (int j = 1; j <= m; j++) {
    		if (i == j) continue;
    		if (abs(a[i] - a[j]) == abs(b[i] - b[j]) && abs(b[i] - b[j]) == 1) {
    			int cur = min(a[i], a[j]), cur2 = min(b[i], b[j]);
    			if (cur % cur2 != 0) cout << -1, exit(0);
            	cout << n / (cur / cur2) + (n % (cur / cur2) != 0), exit(0);
    		}
    	}
    }
    cout << -1;
}

main () {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	int IZIPROBLEM = -1, pro100 = 1, tt = 1;
	while (tt--) {
		Solve();
		exit(pro100 + IZIPROBLEM);
	}
}


#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define ll long long
#define ld long double
#define al 0x3F3F3F3F
#define ull unsigned long long
#define PI pair < int, int >
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
#define resize(v) v.resize(unique(all(v)) - v.begin());
#define int ll

const int mod = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 123;
const int N = 1e6 + 123;
const int INF = al;
const ll INFL = 3e18 + 1;
const double pi = acos(-1.0);
const double eps = 1e-9;

int n, a[101], b[101], m, maxi = -INF, cnt[101], cur;
set <int> s;

inline int gcd(int a, int b) {
	if (!b) return a;
	gcd(b, a % b);
}

inline void boost() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
}

inline void Solve() {
    boost();
    cin >> n >> m;
    if (n == 1) cout << 1, exit(0);
    for (int i = 1; i <= m; i++) cin >> a[i] >> b[i], cnt[b[i]]++, maxi = max(cnt[b[i]], maxi);
    for (int i = 1;  i <= m; i++) if (a[i] == n) cout << b[i], exit(0);
    for (int i = maxi; i <= 100; i++) {
    	bool check = 0;
    	for (int j = 1; j <= m; j++) {
    		if ((a[j] + i - 1) / i != b[j]) check = 1;
    	}
    	if (!check) s.in((n + i - 1) / i), cur = i;
    }
    if (sz(s) != 1) cout << -1, exit(0);
	cout << (n + cur - 1) / cur;
}

main () {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	int IZIPROBLEM = -1, pro100 = 1, tt = 1;
	while (tt--) {
		Solve();
		exit(pro100 + IZIPROBLEM);
	}
}


#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define ll long long
#define ld long double
#define al 0x3F3F3F3F
#define ull unsigned long long
#define PI pair < int, int >
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
#define resize(v) v.resize(unique(all(v)) - v.begin());
#define int ll

const int mod = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 123;
const int N = 1e6 + 123;
const int INF = al;
const ll INFL = 3e18 + 1;
const double pi = acos(-1.0);
const double eps = 1e-9;

int n, m, a[101], b[101], cnt = INF;
set <int> s;

inline int gcd(int a, int b) {
	if (!b) return a;
	gcd(b, a % b);
}

inline void boost() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
}

inline void Solve() {
    boost();
    cin >> n >> m;
    for (int i = 1; i <= m; i++) cin >> a[i] >> b[i];
    for (int i = 1; i <= m; i++) {
    	for (int j = 1; j <= m; j++) {
    		if (i == j) continue;
    		if (abs(a[i] - a[j]) == abs(b[i] - b[j]) && abs(b[i] - b[j]) == 1) {
    			int cur = min(a[i], a[j]), cur2 = min(b[i], b[j]);
    			if (cur % cur2 != 0) cout << -1, exit(0);
            	cout << n / (cur / cur2) + (n % (cur / cur2) != 0), exit(0);
    		}
    	}
    }
}

main () {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	int IZIPROBLEM = -1, pro100 = 1, tt = 1;
	while (tt--) {
		Solve();
		exit(pro100 + IZIPROBLEM);
	}
}


#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define ll long long
#define ld long double
#define al 0x3F3F3F3F
#define ull unsigned long long
#define PI pair < int, int >
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
#define resize(v) v.resize(unique(all(v)) - v.begin());
#define int ll

const int mod = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 123;
const int N = 1e6 + 123;
const int INF = al;
const ll INFL = 3e18 + 1;
const double pi = acos(-1.0);
const double eps = 1e-9;

int n, m, a[101], b[101], cnt = INF;

inline int gcd(int a, int b) {
	if (!b) return a;
	gcd(b, a % b);
}

inline void boost() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
}

inline void Solve() {
    boost();
    cin >> n >> m;
    for (int i = 1; i <= m; i++) cin >> a[i] >> b[i];
    for (int i = 1; i <= m; i++) {
    	for (int j = 1; j <= m; j++) {
    		if (i == j) continue;
    		if (abs(a[i] - a[j]) == abs(b[i] - b[j]) && abs(b[i] - b[j]) == 1) cnt = min(a[i], a[j]) / min(b[i], b[j]);
    	}
    }
    if (cnt == INF) cout << -1, exit(0);
    cout << n / cnt + (n % cnt != 0);
}

main () {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	int IZIPROBLEM = -1, pro100 = 1, tt = 1;
	while (tt--) {
		Solve();
		exit(pro100 + IZIPROBLEM);
	}
}


#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define ll long long
#define ld long double
#define al 0x3F3F3F3F
#define ull unsigned long long
#define PI pair < int, int >
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
#define resize(v) v.resize(unique(all(v)) - v.begin());
#define int ll

const int mod = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 123;
const int N = 1e6 + 123;
const int INF = al;
const ll INFL = 3e18 + 1;
const double pi = acos(-1.0);
const double eps = 1e-9;

int n, m, a[101], b[101], cnt = INF;
set <int> s;

inline int gcd(int a, int b) {
	if (!b) return a;
	gcd(b, a % b);
}

inline void boost() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
}

inline void Solve() {
    boost();
    cin >> n >> m;
    for (int i = 1; i <= m; i++) cin >> a[i] >> b[i];
    for (int i = 1; i <= m; i++) {
    	for (int j = 1; j <= m; j++) {
    		if (i == j) continue;
    		if (abs(a[i] - a[j]) == abs(b[i] - b[j]) && abs(b[i] - b[j]) == 1) {
    			int cur = min(a[i], a[j]), cur2 = min(b[i], b[j]);
    			if (cur % cur2 != 0) cout << -1, exit(0);
            	s.in(n / (cur / cur2) + (n % (cur / cur2) != 0));
        	}
    	}
    }

	cout << (sz(s) == 1 ? *s.begin() : -1);
}

main () {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	int IZIPROBLEM = -1, pro100 = 1, tt = 1;
	while (tt--) {
		Solve();
		exit(pro100 + IZIPROBLEM);
	}
}


#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define ll long long
#define ld long double
#define al 0x3F3F3F3F
#define ull unsigned long long
#define PI pair < int, int >
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
#define resize(v) v.resize(unique(all(v)) - v.begin());
#define int ll

const int mod = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 123;
const int N = 1e6 + 123;
const int INF = al;
const ll INFL = 3e18 + 1;
const double pi = acos(-1.0);
const double eps = 1e-9;

int n, a[101], b[101], m, maxi = -INF, cnt[101], cur;
set <int> s;

inline int gcd(int a, int b) {
	if (!b) return a;
	gcd(b, a % b);
}

inline void boost() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
}

inline void Solve() {
    boost();
    cin >> n >> m;
    if (n == 1) cout << 1, exit(0);
    if (!m) cout << -1, exit(0);
    for (int i = 1; i <= m; i++) cin >> a[i] >> b[i], cnt[b[i]]++, maxi = max(cnt[b[i]], maxi);
    for (int i = maxi; i <= 100; i++) {
    	bool check = 0;
    	for (int j = 1; j <= m; j++) {
    		if ((a[j] + i - 1) / i != b[j]) {
          		check = 1;
     			break;
    		}
    	}
    	if (!check) s.in((n + i - 1) / i), cur = i;
    }
    if (sz(s) != 1) cout << -1, exit(0);
	cout << (n + cur - 1) / cur;
}

main () {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	int IZIPROBLEM = -1, pro100 = 1, tt = 1;
	while (tt--) {
		Solve();
		exit(pro100 + IZIPROBLEM);
	}
}


#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define ll long long
#define ld long double
#define al 0x3F3F3F3F
#define ull unsigned long long
#define PI pair < int, int >
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
#define resize(v) v.resize(unique(all(v)) - v.begin());
#define int ll

const int mod = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 123;
const int N = 1e6 + 123;
const int INF = al;
const ll INFL = 3e18 + 1;
const double pi = acos(-1.0);
const double eps = 1e-9;

int n, a[101], b[101], m, maxi = -INF, cnt[101], cur;
set <int> s;

inline int gcd(int a, int b) {
	if (!b) return a;
	gcd(b, a % b);
}

inline void boost() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
}

inline void Solve() {
    boost();
    cin >> n >> m;
    if (n == 1) cout << 1, exit(0);
    for (int i = 1; i <= m; i++) cin >> a[i] >> b[i], cnt[b[i]]++, maxi = max(cnt[b[i]], maxi);
    for (int i = maxi; i <= 100; i++) {
    	bool check = 0;
    	for (int j = 1; j <= m; j++) {
    		if ((a[j] + i - 1) / i != b[j]) check = 1;
    	}
    	if (!check) s.in((n + i - 1) / i), cur = i;
    }
    if (sz(s) != 1) cout << -1, exit(0);
	cout << (n + cur - 1) / cur;
}

main () {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	int IZIPROBLEM = -1, pro100 = 1, tt = 1;
	while (tt--) {
		Solve();
		exit(pro100 + IZIPROBLEM);
	}
}


#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define ll long long
#define ld long double
#define al 0x3F3F3F3F
#define ull unsigned long long
#define PI pair < int, int >
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
#define resize(v) v.resize(unique(all(v)) - v.begin());
#define int ll

const int mod = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 123;
const int N = 1e6 + 123;
const int INF = al;
const ll INFL = 3e18 + 1;
const double pi = acos(-1.0);
const double eps = 1e-9;

int n, a[101], b[101], m, maxi = -INF, cnt[101], cur;
set <int> s;

inline int gcd(int a, int b) {
	if (!b) return a;
	gcd(b, a % b);
}

inline void boost() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
}

inline void Solve() {
    boost();
    cin >> n >> m;
    if (n == 1) cout << 1, exit(0);
    for (int i = 1; i <= m; i++) cin >> a[i] >> b[i], cnt[b[i]]++, maxi = max(cnt[b[i]], maxi);
    for (int i = 1;  i <= m; i++) if (a[i] == n) cout << b[i], exit(0);
    for (int i = maxi; i <= 100; i++) {
    	bool check = 0;
    	for (int j = 1; j <= m; j++) {
    		if ((a[j] + i - 1) / i != b[j]) {
          		check = 1;
     			break;
    		}
    	}
    	if (!check) s.in((n + i - 1) / i), cur = i;
    }
    if (sz(s) != 1) cout << -1, exit(0);
	cout << (n + cur - 1) / cur;
}

main () {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	int IZIPROBLEM = -1, pro100 = 1, tt = 1;
	while (tt--) {
		Solve();
		exit(pro100 + IZIPROBLEM);
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
typedef pair<int, int> pii;
typedef long long ll;

bool check(int k, vector<pii> &inp) {
	for (int i = 0; i < inp.size(); i++) {
		int a = inp[i].first - 1;
		int must = a / k + 1;
		if (must != inp[i].second) return false;
	}
	return true;
}

int main() {
	int n, k;
	cin >> n >> k;
	vector<pii> vp(k);
	for (int i = 0; i < k; i++) {
		cin >> vp[i].first >> vp[i].second;
	}
	int l = 0, r = 1e9;
	while (l < r - 1) {
		int m = (l + r) / 2;
		if (m <= 3) {
			int a = 1;
		}
		if (check(m, vp)) l = m;
		else r = m;
	}
	if (l != 1 && check(l - 1, vp)) {
		cout << -1;
		return 0;
	}
	if (check(l + 1, vp)) {
		cout << -1;
		return 0;
	}
	cout << (n - 1) / l + 1;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
typedef pair<int, int> pii;
typedef long long ll;

bool check(int k, vector<pii> &inp) {
	for (int i = 0; i < inp.size(); i++) {
		int a = inp[i].first - 1;
		int must = a / k + 1;
		if (must != inp[i].second) return false;
	}
	return true;
}

int main() {
	int n, k;
	cin >> n >> k;
	vector<pii> vp(k);
	for (int i = 0; i < k; i++) {
		cin >> vp[i].first >> vp[i].second;
	}
	set<int> can;
	for (int i = 1; i < 1000; i++) {
		if (check(i, vp)) {
			can.insert((n - 1) / i + 1);
		}
	}
	if (can.size() > 1) {
		cout << -1;
		return 0;
	}
	cout << *can.begin();
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
typedef pair<int, int> pii;
typedef long long ll;

bool check(int k, vector<pii> &inp) {
	for (int i = 0; i < inp.size(); i++) {
		int a = inp[i].first - 1;
		int must = a / k + 1;
		if (must != inp[i].second) return false;
	}
	return true;
}

int main() {
	int n, k;
	cin >> n >> k;
	vector<pii> vp(k);
	for (int i = 0; i < k; i++) {
		cin >> vp[i].first >> vp[i].second;
	}
	int ans = 0, cur = 0;
	for (int i = 1; i < 1000; i++) {
		if (check(i, vp)) ans = i, cur++;
	}
	if (cur > 1) {
		cout << -1;
		return 0;
	}
	cout << (n - 1) / ans + 1;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
typedef pair<int, int> pii;
typedef long long ll;

bool check(int k, vector<pii> &inp) {
	for (int i = 0; i < inp.size(); i++) {
		int a = inp[i].first - 1;
		int must = a / k + 1;
		if (must != inp[i].second) return false;
	}
	return true;
}

int main() {
	int n, k;
	cin >> n >> k;
	vector<pii> vp(k);
	for (int i = 0; i < k; i++) {
		cin >> vp[i].first >> vp[i].second;
	}
	vector<int> can;
	for (int i = 1; i < 1000; i++) {
		if (check(i, vp)) can.push_back(i);
	}
	int ans = 0, cur = 0;
	for (int i = 0; i < can.size(); i++) {
		if (can[i] > n) break;
		ans = can[i];
		cur++;
	}
	if (cur > 1) {
		cout << -1;
		return 0;
	}
	cout << (n - 1) / ans + 1;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
typedef pair<int, int> pii;
typedef long long ll;

bool check(int k, vector<pii> &inp) {
	for (int i = 0; i < inp.size(); i++) {
		int a = inp[i].first - 1;
		int must = a / k + 1;
		if (must != inp[i].second) return false;
	}
	return true;
}

int main() {
	int n, k;
	cin >> n >> k;
	vector<pii> vp(k);
	for (int i = 0; i < k; i++) {
		cin >> vp[i].first >> vp[i].second;
	}
	int ans = 0, cur = 0;
	for (int i = 1; i < 1000; i++) {
		if (check(i, vp)) ans = i, cur++;
	}
	if (cur > 1 || cur == 0) {
		cout << -1;
		return 0;
	}
	cout << (n - 1) / ans + 1;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
typedef pair<int, int> pii;
typedef long long ll;

bool check(int k, vector<pii> &inp) {
	for (int i = 0; i < inp.size(); i++) {
		int a = inp[i].first - 1;
		int must = a / k + 1;
		if (must != inp[i].second) return false;
	}
	return true;
}

int main() {
	int n, k;
	cin >> n >> k;
	vector<pii> vp(k);
	for (int i = 0; i < k; i++) {
		cin >> vp[i].first >> vp[i].second;
	}
	vector<int> can;
	for (int i = 1; i < 1000; i++) {
		if (check(i, vp)) can.push_back(i);
	}
	int ans = 0, cur = 0;
	for (int i = 0; i < can.size(); i++) {
		if (can[i] >= n) break;
		ans = can[i];
		cur++;
	}
	if (cur > 1) {
		cout << -1;
		return 0;
	}
	cout << (n - 1) / ans + 1;
}


#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
typedef pair<int, int> pii;
typedef long long ll;

bool check(int k, vector<pii> &inp) {
	for (int i = 0; i < inp.size(); i++) {
		int a = inp[i].first - 1;
		int must = a / k + 1;
		if (must != inp[i].second) return false;
	}
	return true;
}

int main() {
	int n, k;
	cin >> n >> k;
	vector<pii> vp(k);
	for (int i = 0; i < k; i++) {
		cin >> vp[i].first >> vp[i].second;
	}
	vector<int> can;
	for (int i = 1; i < 1000; i++) {
		if (check(i, vp)) can.push_back(i);
	}
	int ans = 0, cur = 0;
	for (int i = 0; i < can.size(); i++) {
		if (can[i] > n && ans != 0) break;
		ans = can[i];
		cur++;
	}
	if (cur > 1) {
		cout << -1;
		return 0;
	}
	cout << (n - 1) / ans + 1;
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
//	freopen("inputcf.txt", "r", stdin);
//	int testcases;
//	cin >> testcases;
//	while(testcases--)
//	{
		int wanted_flat, n;
		cin >> wanted_flat >> n;
		int apart[100][2] = {0};
		int flat_nums[100000] = {0};
		// inputs in array for clearness
		for (int i = 0; i < n; i++)
		{
			int x, y;
			cin >> x >> y;
			apart[i][0] = x;
			apart[i][1] = y;
		}
//		int last_apart = 0;
//		int floor_num = 0;
		// get possibilities of number of flats in each floor
		int k = 0;
		for (int p = 0; p < n; p++)
		{
			int num = 1;
			while (num <= 100)
			{
				int floor = 0;
				int flat = apart[p][0];
				int adress = apart[p][1];
				while (flat > 0)
				{
					floor++;
					flat -= num;
				}
				if (floor == adress)
				{
					flat_nums[k] = num;
					k++;
				}
//				if (num == 3 || num == 4 || num == 5)
//				{
//					cout << "num = " << num << endl;
//					cout << "floor = " << floor << endl;
//				}
				num++;
			}
		}
		sort(flat_nums, flat_nums+100000, greater<int>());
		int i = 0;
		int c = 0;
		int x = 0;
		int c2 =0;
		while(flat_nums[i] != 0)
		{
			int j = i+1;
			while (flat_nums[j] != 0)
			{
				if (flat_nums[i] == flat_nums[j])
				{
					c++;
//					cout << flat_nums[i] << " " << flat_nums[j] << endl;
//					cout << c << endl;
				}
				j++;
//				cout << flat_nums[j] << endl;
			}
			if (c+1 == n)
			{
				x = flat_nums[i];
				c2++;
			}
			else
				c = 0;
			i++;
		}
//		cout << x << endl;
		if (x == 0 || c2 > 1)
		{
			cout << -1 << endl;
		}
		else
		{
			int out = 0;
			while (wanted_flat > 0)
			{
				out++;
				wanted_flat -= x;
			}
			cout << out << endl;
//		}
//		else
		// can't find num of aparts on each floor
//		if (last_apart == 0)
//			cout << -1 << endl;
		// using num of aparts on each floor find floor of flat
//		else
//		{
//			int num = last_apart/floor_num;
//			int floor = 0;
//			while (wanted_flat > 0)
//			{
//				floor++;
//				wanted_flat -= num;
//			}
//			cout << floor << endl;
//		}
//		for (int i = 0; i < 200; i++)
//		{
//			cout << flat_nums[i] << endl;
//		}

	}
}
/*
 *
		for (int i = 0; i < n; i++)
		{
			for (int j = i; j < n; j++)
			{
				if (abs(apart[i][0] - apart[j][0]) == 1 && abs(apart[i][1] - apart[j][1]) == 1)
				{
					if (apart[i][0] < apart[j][0])
					{
						last_apart = apart[i][0];
						floor_num = apart[i][1];
					}
					else
					{
						last_apart = apart[j][0];
						floor_num = apart[j][1];
					}
				}
			}
		}
 */


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
//	freopen("inputcf.txt", "r", stdin);
//	int testcases;
//	cin >> testcases;
//	while(testcases--)
//	{
		int wanted_flat, n;
		cin >> wanted_flat >> n;
		int apart[100][2] = {0};
		int flat_nums[100000] = {0};
		// inputs in array for clearness
		for (int i = 0; i < n; i++)
		{
			int x, y;
			cin >> x >> y;
			apart[i][0] = x;
			apart[i][1] = y;
		}
//		int last_apart = 0;
//		int floor_num = 0;
		// get possibilities of number of flats in each floor
		int k = 0;
		for (int p = 0; p < n; p++)
		{
			int num = 1;
			while (num <= 100)
			{
				int floor = 0;
				int flat = apart[p][0];
				int adress = apart[p][1];
				while (flat > 0)
				{
					floor++;
					flat -= num;
				}
				if (floor == adress)
				{
					flat_nums[k] = num;
					k++;
				}
//				if (num == 3 || num == 4 || num == 5)
//				{
//					cout << "num = " << num << endl;
//					cout << "floor = " << floor << endl;
//				}
				num++;
			}
		}
		sort(flat_nums, flat_nums+100000, greater<int>());
		int i = 0;
		int c = 0;
		int x = 0;
		int c2 =0;
		while(flat_nums[i] != 0)
		{
			int j = i+1;
			while (flat_nums[j] != 0)
			{
				if (flat_nums[i] == flat_nums[j])
				{
					c++;
//					cout << flat_nums[i] << " " << flat_nums[j] << endl;
//					cout << c << endl;
				}
				else
					break;
				j++;
//				cout << flat_nums[j] << endl;
			}
			if (c+1 == n)
			{
				x = flat_nums[i];
				c2++;
				c = 0;
			}
			else
				c = 0;
			i++;
		}
//		cout << x << endl;

		// there is a solution and it's unique
//		cout << c2 << endl;
		if (x == 0 || c2 > 1)
		{
			cout << -1 << endl;
		}
		else
		{
			int out = 0;
			while (wanted_flat > 0)
			{
				out++;
				wanted_flat -= x;
			}
			cout << out << endl;
//		}
//		else
		// can't find num of aparts on each floor
//		if (last_apart == 0)
//			cout << -1 << endl;
		// using num of aparts on each floor find floor of flat
//		else
//		{
//			int num = last_apart/floor_num;
//			int floor = 0;
//			while (wanted_flat > 0)
//			{
//				floor++;
//				wanted_flat -= num;
//			}
//			cout << floor << endl;
//		}
//		for (int i = 0; i < 200; i++)
//		{
//			cout << flat_nums[i] << endl;
//		}

	}
}
/*
 *
		for (int i = 0; i < n; i++)
		{
			for (int j = i; j < n; j++)
			{
				if (abs(apart[i][0] - apart[j][0]) == 1 && abs(apart[i][1] - apart[j][1]) == 1)
				{
					if (apart[i][0] < apart[j][0])
					{
						last_apart = apart[i][0];
						floor_num = apart[i][1];
					}
					else
					{
						last_apart = apart[j][0];
						floor_num = apart[j][1];
					}
				}
			}
		}
 */


//============================================================================
// Name        : try2.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int wanted_flat, n;
	cin >> wanted_flat >> n;
	int flat[100][2] = {0}, pos_each[100000] = {0}, pos_all[100000] = {0}, out[100000] = {0};

	// inputs

	for (int i = 0; i < n; i++)
	{
		int x, y;
		cin >> x >> y;
		flat[i][0] = x;
		flat[i][1] = y;
	}

	// possible number of flats on each floor for each input

	int index = 0;
	for (int i = 0; i < n; i++)
	{
		for (int num_f = 1; num_f <= 100; num_f++)
		{
			int cur_flat = flat[i][0];
			int given_floor = flat[i][1];
			int floor = 0;
			while (cur_flat > 0)
			{
				cur_flat -= num_f;
				floor++;
			}
			if (floor == given_floor)
			{
				pos_each[index] = num_f;
				index++;
			}
		}
	}

	// possible number of flats for all inputs

	int index2 = 0;
	for (int i = 0; i < index; i++)
	{
		int c = 0;
		for (int j = i+1; j < index; j++)
		{
			if (pos_each[i] == pos_each[j])
				c++;
		}
		if (c+1 == n)
		{
			pos_all[index2] = pos_each[i];
			index2++;
		}
	}

	// check for uniqueness
	for (int i = 0; i < index2; i++)
	{
		int x = wanted_flat;
		int floor = 0;
		while (x > 0)
		{
			x -= pos_all[i];
			floor++;
		}
		out[i] = floor;
	}
	int count = 0;
	for (int i = 0; i < index2; i++)
	{
		for (int j = i +1; j < index2; j++)
		{
			if (out[i] != out[j])
				count++;
		}
	}
	if (wanted_flat == 1)
		cout << 1 << endl;
	else if (count != 0 || n == 0)
		cout << -1 << endl;
	else
		cout << out[0] << endl;

	return 0;
}
//	for (int i = 0; i < 10; i++)
//	{
//		cout << pos_each[i] << endl;
//	}
//for (int i = 0; i < 10; i++)
//{
//	cout << pos_all[i] << endl;
//}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
//	freopen("inputcf.txt", "r", stdin);
//	int testcases;
//	cin >> testcases;
//	while(testcases--)
//	{
		int flat, n;
		cin >> flat >> n;
		int apart[100][2] = {0};
		// inputs in array for clearness
		for (int i = 0; i < n; i++)
		{
			int x, y;
			cin >> x >> y;
			apart[i][0] = x;
			apart[i][1] = y;
		}
		int last_apart = 0;
		int floor_num = 0;
		// find numbers of flats in each floor using last_flat on floor / floor_num
		for (int i = 0; i < n; i++)
		{
			for (int j = i; j < n; j++)
			{
				if (abs(apart[i][0] - apart[j][0]) == 1 && abs(apart[i][1] - apart[j][1]) == 1)
				{
					if (apart[i][0] < apart[j][0])
					{
						last_apart = apart[i][0];
						floor_num = apart[i][1];
					}
					else
					{
						last_apart = apart[j][0];
						floor_num = apart[j][1];
					}
				}
			}
		}
		// can't find num of aparts on each floor
		if (last_apart == 0)
			cout << -1 << endl;
		// using num of aparts on each floor find floor of flat
		else
		{
			int num = last_apart/floor_num;
			int floor = 0;
			while (flat > 0)
			{
				floor++;
				flat -= num;
			}
			cout << floor << endl;
		}
//		for (int i = 0; i < n; i++)
//		{
//			cout << apart[i][0] << " " << apart[i][1] << endl;
//		}

//	}
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
//	freopen("inputcf.txt", "r", stdin);
//	int testcases;
//	cin >> testcases;
//	while(testcases--)
//	{
		int wanted_flat, n;
		cin >> wanted_flat >> n;
		if (wanted_flat == 1)
		{
			cout << 1 << endl;
			return 0;
		}
		int apart[100][2] = {0};
		int flat_nums[100000] = {0};
		// inputs in array for clearness
		for (int i = 0; i < n; i++)
		{
			int x, y;
			cin >> x >> y;
			apart[i][0] = x;
			apart[i][1] = y;
		}
//		int last_apart = 0;
//		int floor_num = 0;
		// get possibilities of number of flats in each floor
		int k = 0;
		for (int p = 0; p < n; p++)
		{
			int num = 1;
			while (num <= 100)
			{
				int floor = 0;
				int flat = apart[p][0];
				int adress = apart[p][1];
				while (flat > 0)
				{
					floor++;
					flat -= num;
				}
				if (floor == adress)
				{
					flat_nums[k] = num;
					k++;
				}
//				if (num == 3 || num == 4 || num == 5)
//				{
//					cout << "num = " << num << endl;
//					cout << "floor = " << floor << endl;
//				}
				num++;
			}
		}
		sort(flat_nums, flat_nums+100000, greater<int>());
		int i = 0;
		int c = 0;
		int x = 0;
		int c2 =0;
		while(flat_nums[i] != 0)
		{
			int j = i+1;
			while (flat_nums[j] != 0)
			{
				if (flat_nums[i] == flat_nums[j])
				{
					c++;
//					cout << flat_nums[i] << " " << flat_nums[j] << endl;
//					cout << c << endl;
				}
				else
					break;
				j++;
//				cout << flat_nums[j] << endl;
			}
			if (c+1 == n)
			{
				x = flat_nums[i];
				c2++;
				c = 0;
			}
			else
				c = 0;
			i++;
		}
//		cout << x << endl;

		// there is a solution and it's unique
//		cout << c2 << endl;
		if (x == 0 || c2 > 1)
		{
			cout << -1 << endl;
		}
		else
		{
			int out = 0;
			while (wanted_flat > 0)
			{
				out++;
				wanted_flat -= x;
			}
			cout << out << endl;
//		}
//		else
		// can't find num of aparts on each floor
//		if (last_apart == 0)
//			cout << -1 << endl;
		// using num of aparts on each floor find floor of flat
//		else
//		{
//			int num = last_apart/floor_num;
//			int floor = 0;
//			while (wanted_flat > 0)
//			{
//				floor++;
//				wanted_flat -= num;
//			}
//			cout << floor << endl;
//		}
//		for (int i = 0; i < 200; i++)
//		{
//			cout << flat_nums[i] << endl;
//		}

	}
}
/*
 *
		for (int i = 0; i < n; i++)
		{
			for (int j = i; j < n; j++)
			{
				if (abs(apart[i][0] - apart[j][0]) == 1 && abs(apart[i][1] - apart[j][1]) == 1)
				{
					if (apart[i][0] < apart[j][0])
					{
						last_apart = apart[i][0];
						floor_num = apart[i][1];
					}
					else
					{
						last_apart = apart[j][0];
						floor_num = apart[j][1];
					}
				}
			}
		}
 */


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {
//	freopen("inputcf.txt", "r", stdin);
//	int testcases;
//	cin >> testcases;
//	while(testcases--)
//	{
		int wanted_flat, n;
		cin >> wanted_flat >> n;
		int apart[100][2] = {0};
		int flat_nums[100000] = {0};
		// inputs in array for clearness
		for (int i = 0; i < n; i++)
		{
			int x, y;
			cin >> x >> y;
			apart[i][0] = x;
			apart[i][1] = y;
		}
//		int last_apart = 0;
//		int floor_num = 0;
		// get possibilities of number of flats in each floor
		int k = 0;
		for (int p = 0; p < n; p++)
		{
			int num = 1;
			while (num <= 100)
			{
				int floor = 0;
				int flat = apart[p][0];
				int adress = apart[p][1];
				while (flat > 0)
				{
					floor++;
					flat -= num;
				}
				if (floor == adress)
				{
					flat_nums[k] = num;
					k++;
				}
//				if (num == 3 || num == 4 || num == 5)
//				{
//					cout << "num = " << num << endl;
//					cout << "floor = " << floor << endl;
//				}
				num++;
			}
		}
		sort(flat_nums, flat_nums+100000, greater<int>());
		int i = 0;
		int c = 0;
		int x = 0;
		int c2 =0;

		// shof el possible flat numbers on each floor el moshtarak ya3ny law two given flats and their floor nums have the same possible number of flats on each floor

		while(flat_nums[i] != 0)
		{
			int j = i+1;
			while (flat_nums[j] != 0)
			{
				if (flat_nums[i] == flat_nums[j])
				{
					c++;
//					cout << flat_nums[i] << " " << flat_nums[j] << endl;
//					cout << c << endl;
				}
				else
					break;
				j++;
//				cout << flat_nums[j] << endl;
			}

			//feh possible number of flats yenfa3 le kol el given inputs

			if (c+1 == n)
			{
				x = flat_nums[i];
				c2++;
			}
			c = 0;
			i++;
		}
//		cout << x << endl;

		// there is a solution and it's unique
//		cout << c2 << endl;
		if (wanted_flat == 1)
			cout << 1 << endl;
		else if (x == 0 || c2 > 1)
		{
			cout << -1 << endl;
		}
		else
		{
			int out = 0;
			while (wanted_flat > 0)
			{
				out++;
				wanted_flat -= x;
			}
			cout << out << endl;
//		}
//		else
		// can't find num of aparts on each floor
//		if (last_apart == 0)
//			cout << -1 << endl;
		// using num of aparts on each floor find floor of flat
//		else
//		{
//			int num = last_apart/floor_num;
//			int floor = 0;
//			while (wanted_flat > 0)
//			{
//				floor++;
//				wanted_flat -= num;
//			}
//			cout << floor << endl;
//		}
//		for (int i = 0; i < 200; i++)
//		{
//			cout << flat_nums[i] << endl;
//		}

	}
}
/*
 *
		for (int i = 0; i < n; i++)
		{
			for (int j = i; j < n; j++)
			{
				if (abs(apart[i][0] - apart[j][0]) == 1 && abs(apart[i][1] - apart[j][1]) == 1)
				{
					if (apart[i][0] < apart[j][0])
					{
						last_apart = apart[i][0];
						floor_num = apart[i][1];
					}
					else
					{
						last_apart = apart[j][0];
						floor_num = apart[j][1];
					}
				}
			}
		}
 */


#include <iostream>

using namespace std;

int main()
{
    long long n, k, m, f, mr = 0, ls = 1e15;
    cin >> n >> m;
    for (int j = 0; j < m; j++) {
        cin >> k >> f;
        if (f != 1) {
            ls = min(ls, k / (f - 1) + (k % (f - 1) != 0));
        }
        mr = max(mr, k / f + (k % f != 0));
        //cout << mn << " " << mx << '\n';
    }
    long long a = n / mr + (n % mr != 0);
    for (int j = mr + 1; j < ls; j++) {
        if (a != n / j + (n % j != 0)) {
            cout << -1;
            return 0;
        }
    }
    cout << a;
}


#include <iostream>

using namespace std;

int main()
{
    long long n, k, m, f, mr = 0, ls = 1e15;
    cin >> n >> m;
    for (int j = 0; j < m; j++) {
        cin >> k >> f;
        if (f != 1) {
            ls = min(ls, k / (f - 1) + (k % (f - 1) != 0));
        }
        mr = max(mr, k / f + (k % f != 0));
        //cout << mn << " " << mx << '\n';
    }
    long long a = n / mr + (n % mr != 0);
    if (a != n / (ls - 1) + (n % (ls - 1) != 0)) {
        cout << -1;
        return 0;
    }
    cout << a;
}


#include <iostream>

using namespace std;

int main()
{
    long long n, k, m, f, mr = 0, ls = 1e15;
    cin >> n >> m;
    for (int j = 0; j < m; j++) {
        cin >> k >> f;
        if (f != 1) {
            ls = min(ls, k / (f - 1) + (k % (f - 1) != 0));
        }
        mr = max(mr, k / f + (k % f != 0));
        //cout << mn << " " << mx << '\n';
    }
    long long a = n / max((long long)1, mr) + (n % max((long long)1, mr) != 0);
    if (ls > 1 && a != n / (ls - 1) + (n % (ls - 1) != 0)) {
        cout << -1;
        return 0;
    }
    cout << a;
}


#include <iostream>

using namespace std;

int main()
{
    long long n, k, m, f, mr = 0, ls = 1e15;
    cin >> n >> m;
    for (int j = 0; j < m; j++) {
        cin >> k >> f;
        if (f != 1) {
            ls = min(ls, k / (f - 1) + (k % (f - 1) != 0));
        }
        mr = max(mr, k / f + (k % f != 0));
        //cout << mn << " " << mx << '\n';
    }
    if (mr + 1 == ls) {
        cout << n / mr + (n % mr != 0);
    }
    else {
        cout << -1;
    }
}


#include <iostream>

using namespace std;

int main()
{
    long long n, k, m, f, mr = 0, ls = 1e15;
    cin >> n >> m;
    for (int j = 0; j < m; j++) {
        cin >> k >> f;
        if (f != 1) {
            ls = min(ls, k / (f - 1) + (k % (f - 1) != 0));
        }
        mr = max(mr, k / f + (k % f != 0));
        //cout << mn << " " << mx << '\n';
    }
    long long a = n / mr + (n % mr != 0);
    if (ls > 1 && a != n / (ls - 1) + (n % (ls - 1) != 0)) {
        cout << -1;
        return 0;
    }
    cout << a;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	int n, m;
	cin >> n >> m;
	if (n == 1) {
		cout << 1;
		return 0;
	}
	vector<pair<int, int>> q(m);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		if (a == n) {
			cout << b;
			return 0;
		}
		q[i] = make_pair(a, b);
	}
	q.push_back(make_pair(1, 1));
	set<int> ans;
	for (int i = 1; i <= 100; i++) {
		bool b = true;
		for (int j = 0; j < m; j++) {
			if (q[j].second != 1) {
				if (q[j].first / i + (q[j].first % i == 0 ? 0 : 1) != q[j].second) {
					b = false;
					break;
				}
			}
			else {
				if (q[j].first > i) {
					b = false;
					break;
				}
			}
		}
		if (b)ans.insert(n / i + (n % i == 0 ? 0 : 1));
	}
	if (ans.size() == 1) {
		cout << *ans.begin();
	}
	else {
		cout << -1;
	}
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	int n, m;
	cin >> n >> m;
	if (n == 1) {
		cout << 1;
		return 0;
	}
	vector<pair<int, int>> q(m);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		if (a == n) {
			cout << b;
			return 0;
		}
		q[i] = make_pair(a, b);
	}
	q.push_back(make_pair(1, 1));
	vector<int> ans;
	for (int i = 1; i <= 100; i++) {
		bool b = true;
		for (int j = 0; j < m; j++) {
			if (q[j].second != 1) {
				if (q[j].first / i + (q[j].first % i == 0 ? 0 : 1) != q[j].second) {
					b = false;
					break;
				}
			}
			else {
				if (q[j].first > i) {
					b = false;
					break;
				}
			}
		}
		if (b)ans.push_back(i);
	}
	if (ans.size() == 1) {
		cout << n / ans[0] + (n % ans[0] == 0 ? 0 : 1);
	}
	else {
		cout << -1;
	}
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> q(m);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		q[i] = make_pair(a, b);
	}
	vector<int> ans;
	for (int i = 1; i <= 100; i++) {
		bool b = true;
		for (int j = 0; j < m; j++) {
			if (q[j].second != 1){
				if (q[j].first / i+ (q[j].first % i == 0 ? 0 : 1) != q[j].second) {
					b = false;
					break;
				}
		}
			else {
				if (q[j].first > i) {
					b = false;
					break;
				}
			}
		}
		if (b)ans.push_back(i);
	}
	if (ans.size() == 1) {
		cout << n / ans[0] + (n % ans[0] == 0 ? 0 : 1);
	}
	else {
		cout << -1;
	}
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	int n, m;
	cin >> n >> m;
	if (n == 1) {
		cout << 1;
		return 0;
	}
	vector<pair<int, int>> q(m);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		q[i] = make_pair(a, b);
	}
	q.push_back(make_pair(1, 1));
	vector<int> ans;
	for (int i = 1; i <= 100; i++) {
		bool b = true;
		for (int j = 0; j < m; j++) {
			if (q[j].second != 1){
				if (q[j].first / i+ (q[j].first % i == 0 ? 0 : 1) != q[j].second) {
					b = false;
					break;
				}
		}
			else {
				if (q[j].first > i) {
					b = false;
					break;
				}
			}
		}
		if (b)ans.push_back(i);
	}
	if (ans.size() == 1) {
		cout << n / ans[0] + (n % ans[0] == 0 ? 0 : 1);
	}
	else {
		cout << -1;
	}
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	int n, m;
	cin >> n >> m;
	vector<pair<int,int>> q(m);
	for (int i = 0; i < m; i++) {
		cin >> q[i].first >> q[i].second;
	}
	sort(q.begin(), q.end());
	for (int i = 1; i < m; i++) {
		if (q[i].second == q[i - 1].second + 1 && q[i].first == q[i-1].first + 1) {
			int nff = q[i - 1].first / q[i - 1].second;
			cout << n / nff + (n % nff == 0 ? 0 : 1);
			return 0;
		}
	}
	cout << -1;
	return 0;
}


#include <bits/stdc++.h>

#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef ld typ;
typedef string str;

struct point
{
    ld x, y;
};

struct vec
{
    ld a, b;
};

struct line
{
    ld a, b, c;
};

const ll MaxN = 1e6;
const ld eps = 1e-8;
const ll MaxNN = 1e3;

void build(ll, ll, ll);
ll _max(ll, ll, ll, ll, ll);
void update(ll, ll, ll, ll, ll, ll);
typ sqr(typ);
void start();
void extended(int);
point cin_point();
void cout_point(point);
point n_point(point, point);
vec mv(point, point);
line ml(point, point);
typ croos(vec, vec);
typ skalar(vec, vec);

int a[100000], d[400000], updateb[400000];

int main()
{
    start();

    ll a[110];
    ll n, m, f, k, mn, mx;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> k >> f;
        if (k == n)
        {
            cout << f;
            return 0;
        }
        else
            a[k] = f;
        if (k < n)
            mn = f;
        if (k > n)
            mx = f;
    }
    if (mn == mx)
        return cout << mn << endl, 0;
    for (int i = 1; i < n; i++)
        if (a[i] - a[i - 1] == 1)
        {
            //i - 1 - ��������� �������� �� a[i - 1] �����
            if ((i - 1) % a[i - 1])
                return cout << -1 << endl, 0;
            ll b = (i - 1) / a[i - 1];
            cout << (n - 1) / b + 1 << endl;
            return 0;
        }
    cout << -1 << endl;
    return 0;
}

void build(ll v, ll tl, ll tr)
{
    if (tl == tr)
        d[v] = a[tl];
    else
    {
        ll tm = (tl + tr) / 2;
        build(v * 2, tl, tm);
        build(v * 2 + 1, tm + 1, tr);
        d[v] = max(d[v * 2], d[v * 2 + 1]);
    }
}

ll _max(ll v, ll tl, ll tr, ll l, ll r)
{
    if (l > r)
        return 0;
    if (tl == l && tr == r)
        return d[v] + updateb[v];
    ll tm = (tl + tr) / 2;
    return max(_max(v * 2, tl, tm, l, min(r, tm)), _max(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r)) + updateb[v];
}

void update(ll v, ll tl, ll tr, ll l, ll r, ll s)
{
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        updateb[v] += s;
        return;
    }
    ll tm = (tl + tr) / 2;
    update(v * 2, tl, tm, l, min(r, tm), s);
    update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, s);
}

ld sqr(ld a)
{
    return a * a;
}

void start()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
}

void extended(int n)
{
    cout << setprecision(n) << fixed;
}

point cin_point()
{
    point a;
    cin >> a.x >> a.y;
    return a;
}

void cout_point(point a)
{
    cout << a.x << ' ' << a.y << endl;
}

point n_point(point a, point b)
{
    point n;
    n.x = a.x;
    n.y = b.y;
    return n;
}

vec mv(point st, point fn)
{
    vec v;
    v.a = fn.x - st.x;
    v.b = fn.y - st.y;
    return v;
}

line ml(point a, point b)
{
    line l;
    l.a = b.y - a.y;
    l.b = a.x - b.x;
    l.c = -l.a * a.x - l.b * a.y;
    return l;
}

typ skalar(vec a, vec b)
{
    return a.a * b.a + a.b * b.b;
}

typ cross(vec a, vec b)
{
    return a.a * b.b - a.b * b.a;
}