#include<bits/stdc++.h>
#include <complex>

#define Write freopen("out.txt","w",stdout)
#define Read freopen("in.txt","r",stdin)

#define si(a)           scanf("%d",&a)
#define sii(a,b)        scanf("%d %d",&a,&b)
#define siii(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define sl(a)           scanf("%lld",&a)
#define sll(a,b)        scanf("%lld %lld",&a,&b)
#define slll(a,b,c)     scanf("%lld %lld %lld",&a,&b,&c)

#define m_p make_pair
#define ll long long

#define lim 10000000
#define mod 100007
#define dist(ax,ay,bx,by)   ((ax-bx)*(ax-bx)+(ay-by)*(ay-by))
/*Geometry*/
#define X real()
#define Y imag()
/*Geometry*/

using namespace std;

typedef complex < ll > cmp;
set<int>s;
set<int>::iterator it;
//char str[100000];
//map<char,int>mp;
//map<char,int>::iterator it;
//int main()
//{
//    scanf("%s",&str);
//    ll ln=strlen(str);
//    bool flag=false;
//    bool check=false;
//    for(ll i=0; i<ln-2; i++)
//    {
//        if(str[i]!='a'&&str[i]!='e'&&str[i]!='i'&&str[i]!='o'&&str[i]!='u'
//                &&str[i+1]!='a'&&str[i+1]!='e'&&str[i+1]!='i'&&str[i+1]!='o'&&str[i+1]!='u'
//                &&str[i+2]!='a'&&str[i+2]!='e'&&str[i+2]!='i'&&str[i+2]!='o'&&str[i+2]!='u'
//          )
//        {
//            if(str[i]==str[i+1]&&str[i]==str[i+2])
//            {
//                check=true;
//            }
//            else flag=true;
//        }
//    }
//    if(check&&flag)
//    {
//        for(ll i=0; i<ln; i++)
//        {
//            if(str[i]=='a'||str[i]=='e'||str[i]=='i'
//                ||str[i]=='o'||str[i]=='u')
//            {
//                printf("%c",str[i]);
//                mp.clear();
//            }
//            else
//            {
//                mp[str[i]]++;
//                if(mp.size()==3)
//                {
//                    printf(" %c",str[i]);
//                    mp.clear();
//                    mp[str[i]]++;
//                }
//                else if(mp.size()==2)
//                {
//                    it=mp.begin();
//                   int a=it->second;
//                    it++;
//                    a+=it->second;
//                    if(a==3)
//                    {
//                        printf(" %c",str[i]);
//                         mp.clear();
//                         mp[str[i]]++;
//
//                    }
//                    else printf("%c",str[i]);
//                }
//                else {
//                        printf("%c",str[i]);
//            }
//        }
//    }
//    }
//    else if(flag)
//    {
//        for(ll i=0; i<ln; i++)
//        {
//             if(str[i]=='a'||str[i]=='e'||str[i]=='i'
//                ||str[i]=='o'||str[i]=='u')
//            {
//                printf("%c",str[i]);
//                mp.clear();
//            }
//            else
//            {
//
//                mp[str[i]]++;
//                if(mp.size()==3)
//                {
//                    printf(" %c",str[i]);
//                    mp.clear();
//                    mp[str[i]]++;
//                }
//                else if(mp.size()==2)
//                {
//                    it=mp.begin();
//                   int a=it->second;
//                    it++;
//                    a+=it->second;
//                    if(a==3)
//                    {
//                        printf(" %c",str[i]);
//                         mp.clear();
//                         mp[str[i]]++;
//
//                    }
//                    else printf("%c",str[i]);
//                }
//
//                else {
//                        printf("%c",str[i]);
//            }
//        }
//        }
//
//
//    }
//    else
//    {
//        printf("%s\n",str);
//    }
//
//}
int arr[1000];
int check[1000];
int main()
{
    int a,b;
    sii(a,b);
    for(int i=0;i<b;i++){
        int x,y;
        sii(x,y);
        arr[x]=y;
        check[i]=x;
    }
    int cnt=0,ans;
    int flag=true;
    for(int i=1;i<=100;i++)
    {    flag=true;
        for(int j=0;j<b;j++)
        {
            int ase=arr[check[j]];

            int lagbe=(check[j]/i);
            if(check[j]%i!=0) lagbe++;

          if(ase!=lagbe) flag=false;
        }
        if(flag) {

        ans=i;
        int p=a/ans;
        if(a%ans!=0) p++;
        s.insert(p);
        }

    }
    if(s.size()==1)
    {
        it=s.begin();
        cout<<(*it)<<endl;
    }
    else{
        cout<<"-1"<<endl;
    }

}


#include<bits/stdc++.h>
#include <complex>

#define Write freopen("out.txt","w",stdout)
#define Read freopen("in.txt","r",stdin)

#define si(a)           scanf("%d",&a)
#define sii(a,b)        scanf("%d %d",&a,&b)
#define siii(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define sl(a)           scanf("%lld",&a)
#define sll(a,b)        scanf("%lld %lld",&a,&b)
#define slll(a,b,c)     scanf("%lld %lld %lld",&a,&b,&c)

#define m_p make_pair
#define ll long long

#define lim 10000000
#define mod 100007
#define dist(ax,ay,bx,by)   ((ax-bx)*(ax-bx)+(ay-by)*(ay-by))
/*Geometry*/
#define X real()
#define Y imag()
/*Geometry*/

using namespace std;

typedef complex < ll > cmp;
//char str[100000];
//map<char,int>mp;
//map<char,int>::iterator it;
//int main()
//{
//    scanf("%s",&str);
//    ll ln=strlen(str);
//    bool flag=false;
//    bool check=false;
//    for(ll i=0; i<ln-2; i++)
//    {
//        if(str[i]!='a'&&str[i]!='e'&&str[i]!='i'&&str[i]!='o'&&str[i]!='u'
//                &&str[i+1]!='a'&&str[i+1]!='e'&&str[i+1]!='i'&&str[i+1]!='o'&&str[i+1]!='u'
//                &&str[i+2]!='a'&&str[i+2]!='e'&&str[i+2]!='i'&&str[i+2]!='o'&&str[i+2]!='u'
//          )
//        {
//            if(str[i]==str[i+1]&&str[i]==str[i+2])
//            {
//                check=true;
//            }
//            else flag=true;
//        }
//    }
//    if(check&&flag)
//    {
//        for(ll i=0; i<ln; i++)
//        {
//            if(str[i]=='a'||str[i]=='e'||str[i]=='i'
//                ||str[i]=='o'||str[i]=='u')
//            {
//                printf("%c",str[i]);
//                mp.clear();
//            }
//            else
//            {
//                mp[str[i]]++;
//                if(mp.size()==3)
//                {
//                    printf(" %c",str[i]);
//                    mp.clear();
//                    mp[str[i]]++;
//                }
//                else if(mp.size()==2)
//                {
//                    it=mp.begin();
//                   int a=it->second;
//                    it++;
//                    a+=it->second;
//                    if(a==3)
//                    {
//                        printf(" %c",str[i]);
//                         mp.clear();
//                         mp[str[i]]++;
//
//                    }
//                    else printf("%c",str[i]);
//                }
//                else {
//                        printf("%c",str[i]);
//            }
//        }
//    }
//    }
//    else if(flag)
//    {
//        for(ll i=0; i<ln; i++)
//        {
//             if(str[i]=='a'||str[i]=='e'||str[i]=='i'
//                ||str[i]=='o'||str[i]=='u')
//            {
//                printf("%c",str[i]);
//                mp.clear();
//            }
//            else
//            {
//
//                mp[str[i]]++;
//                if(mp.size()==3)
//                {
//                    printf(" %c",str[i]);
//                    mp.clear();
//                    mp[str[i]]++;
//                }
//                else if(mp.size()==2)
//                {
//                    it=mp.begin();
//                   int a=it->second;
//                    it++;
//                    a+=it->second;
//                    if(a==3)
//                    {
//                        printf(" %c",str[i]);
//                         mp.clear();
//                         mp[str[i]]++;
//
//                    }
//                    else printf("%c",str[i]);
//                }
//
//                else {
//                        printf("%c",str[i]);
//            }
//        }
//        }
//
//
//    }
//    else
//    {
//        printf("%s\n",str);
//    }
//
//}
int arr[1000];
int check[1000];
set<int>s;
set<int>::iterator it;
int main()
{
    int a,b;
    sii(a,b);
    for(int i=0; i<b; i++)
    {
        int x,y;
        sii(x,y);
        arr[x]=y;
        check[i]=x;
    }
    int cnt=0,ans=-1;
    int flag=true;
    for(int i=1; i<=100; i++)
    {
        flag=true;
        for(int j=0; j<b; j++)
        {
            int ase=arr[check[j]];
            int lagbe=(check[j]/i);
            int p=lagbe+1;
            if(check[j]%i!=0&&check[j]<p*i)
            {
                lagbe++;
            }

            if(ase!=lagbe) flag=false;
        }
        if(flag)
        {

            ans=i;
            int p=a/ans;
        int l=p+1;
        if(a%ans!=0&&a<l*ans) p++;
        s.insert(p);
        }

    }
    ///cout<<s.size()<<endl;
    if(s.size()==1)
    {
        it=s.begin();
     cout<<(*it)<<endl;
    }
    else
    {
        cout<<"-1"<<endl;
    }

}


#include<bits/stdc++.h>
#include <complex>

#define Write freopen("out.txt","w",stdout)
#define Read freopen("in.txt","r",stdin)

#define si(a)           scanf("%d",&a)
#define sii(a,b)        scanf("%d %d",&a,&b)
#define siii(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define sl(a)           scanf("%lld",&a)
#define sll(a,b)        scanf("%lld %lld",&a,&b)
#define slll(a,b,c)     scanf("%lld %lld %lld",&a,&b,&c)

#define m_p make_pair
#define ll long long

#define lim 10000000
#define mod 100007
#define dist(ax,ay,bx,by)   ((ax-bx)*(ax-bx)+(ay-by)*(ay-by))
/*Geometry*/
#define X real()
#define Y imag()
/*Geometry*/

using namespace std;

typedef complex < ll > cmp;
//char str[100000];
//map<char,int>mp;
//map<char,int>::iterator it;
//int main()
//{
//    scanf("%s",&str);
//    ll ln=strlen(str);
//    bool flag=false;
//    bool check=false;
//    for(ll i=0; i<ln-2; i++)
//    {
//        if(str[i]!='a'&&str[i]!='e'&&str[i]!='i'&&str[i]!='o'&&str[i]!='u'
//                &&str[i+1]!='a'&&str[i+1]!='e'&&str[i+1]!='i'&&str[i+1]!='o'&&str[i+1]!='u'
//                &&str[i+2]!='a'&&str[i+2]!='e'&&str[i+2]!='i'&&str[i+2]!='o'&&str[i+2]!='u'
//          )
//        {
//            if(str[i]==str[i+1]&&str[i]==str[i+2])
//            {
//                check=true;
//            }
//            else flag=true;
//        }
//    }
//    if(check&&flag)
//    {
//        for(ll i=0; i<ln; i++)
//        {
//            if(str[i]=='a'||str[i]=='e'||str[i]=='i'
//                ||str[i]=='o'||str[i]=='u')
//            {
//                printf("%c",str[i]);
//                mp.clear();
//            }
//            else
//            {
//                mp[str[i]]++;
//                if(mp.size()==3)
//                {
//                    printf(" %c",str[i]);
//                    mp.clear();
//                    mp[str[i]]++;
//                }
//                else if(mp.size()==2)
//                {
//                    it=mp.begin();
//                   int a=it->second;
//                    it++;
//                    a+=it->second;
//                    if(a==3)
//                    {
//                        printf(" %c",str[i]);
//                         mp.clear();
//                         mp[str[i]]++;
//
//                    }
//                    else printf("%c",str[i]);
//                }
//                else {
//                        printf("%c",str[i]);
//            }
//        }
//    }
//    }
//    else if(flag)
//    {
//        for(ll i=0; i<ln; i++)
//        {
//             if(str[i]=='a'||str[i]=='e'||str[i]=='i'
//                ||str[i]=='o'||str[i]=='u')
//            {
//                printf("%c",str[i]);
//                mp.clear();
//            }
//            else
//            {
//
//                mp[str[i]]++;
//                if(mp.size()==3)
//                {
//                    printf(" %c",str[i]);
//                    mp.clear();
//                    mp[str[i]]++;
//                }
//                else if(mp.size()==2)
//                {
//                    it=mp.begin();
//                   int a=it->second;
//                    it++;
//                    a+=it->second;
//                    if(a==3)
//                    {
//                        printf(" %c",str[i]);
//                         mp.clear();
//                         mp[str[i]]++;
//
//                    }
//                    else printf("%c",str[i]);
//                }
//
//                else {
//                        printf("%c",str[i]);
//            }
//        }
//        }
//
//
//    }
//    else
//    {
//        printf("%s\n",str);
//    }
//
//}
int arr[1000];
int check[1000];
int main()
{
    int a,b;
    sii(a,b);
    for(int i=0; i<b; i++)
    {
        int x,y;
        sii(x,y);
        arr[x]=y;
        check[i]=x;
    }
    int cnt=0,ans;
    int flag=true;
    for(int i=1; i<=100; i++)
    {
        flag=true;
        for(int j=0; j<b; j++)
        {
            int ase=arr[check[j]];

            int lagbe=(check[j]/i);
            if(check[j]%i!=0&&lagbe!=0) lagbe++;

            if(ase!=lagbe) flag=false;
        }
        if(flag)
        {
            cnt++;
            ans=i;
        }

    }
    if(cnt==1)
    {
        int p=a/ans;
        if(a%ans!=0) p++;
        cout<<p<<endl;
    }
    else
    {
        cout<<"-1"<<endl;
    }

}


#include<bits/stdc++.h>
#include <complex>

#define Write freopen("out.txt","w",stdout)
#define Read freopen("in.txt","r",stdin)

#define si(a)           scanf("%d",&a)
#define sii(a,b)        scanf("%d %d",&a,&b)
#define siii(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define sl(a)           scanf("%lld",&a)
#define sll(a,b)        scanf("%lld %lld",&a,&b)
#define slll(a,b,c)     scanf("%lld %lld %lld",&a,&b,&c)

#define m_p make_pair
#define ll long long

#define lim 10000000
#define mod 100007
#define dist(ax,ay,bx,by)   ((ax-bx)*(ax-bx)+(ay-by)*(ay-by))
/*Geometry*/
#define X real()
#define Y imag()
/*Geometry*/

using namespace std;

typedef complex < ll > cmp;
//char str[100000];
//map<char,int>mp;
//map<char,int>::iterator it;
//int main()
//{
//    scanf("%s",&str);
//    ll ln=strlen(str);
//    bool flag=false;
//    bool check=false;
//    for(ll i=0; i<ln-2; i++)
//    {
//        if(str[i]!='a'&&str[i]!='e'&&str[i]!='i'&&str[i]!='o'&&str[i]!='u'
//                &&str[i+1]!='a'&&str[i+1]!='e'&&str[i+1]!='i'&&str[i+1]!='o'&&str[i+1]!='u'
//                &&str[i+2]!='a'&&str[i+2]!='e'&&str[i+2]!='i'&&str[i+2]!='o'&&str[i+2]!='u'
//          )
//        {
//            if(str[i]==str[i+1]&&str[i]==str[i+2])
//            {
//                check=true;
//            }
//            else flag=true;
//        }
//    }
//    if(check&&flag)
//    {
//        for(ll i=0; i<ln; i++)
//        {
//            if(str[i]=='a'||str[i]=='e'||str[i]=='i'
//                ||str[i]=='o'||str[i]=='u')
//            {
//                printf("%c",str[i]);
//                mp.clear();
//            }
//            else
//            {
//                mp[str[i]]++;
//                if(mp.size()==3)
//                {
//                    printf(" %c",str[i]);
//                    mp.clear();
//                    mp[str[i]]++;
//                }
//                else if(mp.size()==2)
//                {
//                    it=mp.begin();
//                   int a=it->second;
//                    it++;
//                    a+=it->second;
//                    if(a==3)
//                    {
//                        printf(" %c",str[i]);
//                         mp.clear();
//                         mp[str[i]]++;
//
//                    }
//                    else printf("%c",str[i]);
//                }
//                else {
//                        printf("%c",str[i]);
//            }
//        }
//    }
//    }
//    else if(flag)
//    {
//        for(ll i=0; i<ln; i++)
//        {
//             if(str[i]=='a'||str[i]=='e'||str[i]=='i'
//                ||str[i]=='o'||str[i]=='u')
//            {
//                printf("%c",str[i]);
//                mp.clear();
//            }
//            else
//            {
//
//                mp[str[i]]++;
//                if(mp.size()==3)
//                {
//                    printf(" %c",str[i]);
//                    mp.clear();
//                    mp[str[i]]++;
//                }
//                else if(mp.size()==2)
//                {
//                    it=mp.begin();
//                   int a=it->second;
//                    it++;
//                    a+=it->second;
//                    if(a==3)
//                    {
//                        printf(" %c",str[i]);
//                         mp.clear();
//                         mp[str[i]]++;
//
//                    }
//                    else printf("%c",str[i]);
//                }
//
//                else {
//                        printf("%c",str[i]);
//            }
//        }
//        }
//
//
//    }
//    else
//    {
//        printf("%s\n",str);
//    }
//
//}
int arr[1000];
int check[1000];
int main()
{
    int a,b;
    sii(a,b);
    for(int i=0; i<b; i++)
    {
        int x,y;
        sii(x,y);
        arr[x]=y;
        check[i]=x;
    }
    int cnt=0,ans=-1;
    int flag=true;
    for(int i=1; i<=100; i++)
    {
        flag=true;
        for(int j=0; j<b; j++)
        {
            int ase=arr[check[j]];
            int lagbe=(check[j]/i);
            int p=lagbe+1;
            if(check[j]%i!=0&&check[j]<p*i)
            {
                lagbe++;
            }

            if(ase!=lagbe) flag=false;
        }
        if(flag)
        {
            //cnt++;
            ans=i;
        }

    }
    if(ans!=-1)
    {
        int p=a/ans;
        int l=p+1;
        if(a%ans!=0&&a<l*ans) p++;
        cout<<p<<endl;
    }
    else
    {
        cout<<"-1"<<endl;
    }

}


#include<bits/stdc++.h>
#include <complex>

#define Write freopen("out.txt","w",stdout)
#define Read freopen("in.txt","r",stdin)

#define si(a)           scanf("%d",&a)
#define sii(a,b)        scanf("%d %d",&a,&b)
#define siii(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define sl(a)           scanf("%lld",&a)
#define sll(a,b)        scanf("%lld %lld",&a,&b)
#define slll(a,b,c)     scanf("%lld %lld %lld",&a,&b,&c)

#define m_p make_pair
#define ll long long

#define lim 10000000
#define mod 100007
#define dist(ax,ay,bx,by)   ((ax-bx)*(ax-bx)+(ay-by)*(ay-by))
/*Geometry*/
#define X real()
#define Y imag()
/*Geometry*/

using namespace std;

typedef complex < ll > cmp;
//char str[100000];
//map<char,int>mp;
//map<char,int>::iterator it;
//int main()
//{
//    scanf("%s",&str);
//    ll ln=strlen(str);
//    bool flag=false;
//    bool check=false;
//    for(ll i=0; i<ln-2; i++)
//    {
//        if(str[i]!='a'&&str[i]!='e'&&str[i]!='i'&&str[i]!='o'&&str[i]!='u'
//                &&str[i+1]!='a'&&str[i+1]!='e'&&str[i+1]!='i'&&str[i+1]!='o'&&str[i+1]!='u'
//                &&str[i+2]!='a'&&str[i+2]!='e'&&str[i+2]!='i'&&str[i+2]!='o'&&str[i+2]!='u'
//          )
//        {
//            if(str[i]==str[i+1]&&str[i]==str[i+2])
//            {
//                check=true;
//            }
//            else flag=true;
//        }
//    }
//    if(check&&flag)
//    {
//        for(ll i=0; i<ln; i++)
//        {
//            if(str[i]=='a'||str[i]=='e'||str[i]=='i'
//                ||str[i]=='o'||str[i]=='u')
//            {
//                printf("%c",str[i]);
//                mp.clear();
//            }
//            else
//            {
//                mp[str[i]]++;
//                if(mp.size()==3)
//                {
//                    printf(" %c",str[i]);
//                    mp.clear();
//                    mp[str[i]]++;
//                }
//                else if(mp.size()==2)
//                {
//                    it=mp.begin();
//                   int a=it->second;
//                    it++;
//                    a+=it->second;
//                    if(a==3)
//                    {
//                        printf(" %c",str[i]);
//                         mp.clear();
//                         mp[str[i]]++;
//
//                    }
//                    else printf("%c",str[i]);
//                }
//                else {
//                        printf("%c",str[i]);
//            }
//        }
//    }
//    }
//    else if(flag)
//    {
//        for(ll i=0; i<ln; i++)
//        {
//             if(str[i]=='a'||str[i]=='e'||str[i]=='i'
//                ||str[i]=='o'||str[i]=='u')
//            {
//                printf("%c",str[i]);
//                mp.clear();
//            }
//            else
//            {
//
//                mp[str[i]]++;
//                if(mp.size()==3)
//                {
//                    printf(" %c",str[i]);
//                    mp.clear();
//                    mp[str[i]]++;
//                }
//                else if(mp.size()==2)
//                {
//                    it=mp.begin();
//                   int a=it->second;
//                    it++;
//                    a+=it->second;
//                    if(a==3)
//                    {
//                        printf(" %c",str[i]);
//                         mp.clear();
//                         mp[str[i]]++;
//
//                    }
//                    else printf("%c",str[i]);
//                }
//
//                else {
//                        printf("%c",str[i]);
//            }
//        }
//        }
//
//
//    }
//    else
//    {
//        printf("%s\n",str);
//    }
//
//}
int arr[1000];
int check[1000];
int main()
{
    int a,b;
    sii(a,b);
    for(int i=0;i<b;i++){
        int x,y;
        sii(x,y);
        arr[x]=y;
        check[i]=x;
    }
    int cnt=0,ans;
    int flag=true;
    for(int i=1;i<=100;i++)
    {    flag=true;
        for(int j=0;j<b;j++)
        {
            int ase=arr[check[j]];

            int lagbe=(check[j]/i);
            if(check[j]%i!=0) lagbe++;

          if(ase!=lagbe) flag=false;
        }
        if(flag) {
                cnt++;
        ans=i;
        }

    }
    if(cnt==1)
    {
        int p=a/ans;
        if(a%ans!=0) p++;
        cout<<p<<endl;
    }
    else{
        cout<<"-1"<<endl;
    }

}


//
//  main.cpp
//  A
//
//  Created by Eleonora Rocchi on 17/09/17.
//  Copyright © 2017 Eleonora Rocchi. All rights reserved.
//

#include <iostream>
#include <stdio.h>
using namespace std;
int v[1000];
int N, M, start = 1;
int main() {
   cin >> N >> M;
   int x,y;
   for(int i =0; i < M; i++){
      cin >> x >> y;
      v[x] = y;
   }
   int way = 0,save = 1000;
   for(int i = 1; i < N; i++){
      bool contr = false;
      for(int j = 1; j < N; j++){
         if(v[j] != 0){
            int floor_ex =  j/i;
            if ( j % i !=0)floor_ex ++;
            //cout << "floor" << i << "  ex    " << floor_ex << "flat  "<< j<< endl;
            //cout << floor_ex <<" "<<v[j] << endl;
            if(floor_ex != v[j]){
               contr = true;
               break;
            }
         }
      }
      if(!contr) {
         way++;
         save = N/i;
         if (N % i != 0)save++;
      }
   }

   if(way == 1) cout << save;
   else cout << "-1";
   return 0;
}


//
//  main.cpp
//  A
//
//  Created by Eleonora Rocchi on 17/09/17.
//  Copyright © 2017 Eleonora Rocchi. All rights reserved.
//

#include <iostream>
#include <stdio.h>
using namespace std;
int v[1000];
int N, M, start = 1;
int main() {
   cin >> N >> M;
   int x,y;
   for(int i =0; i < M; i++){
      cin >> x >> y;
      v[x] = y;
   }
   int way = 0,save = 1000;
   for(int i = 1; i < N; i++){
      bool contr = false;
      for(int j = 1; j < N; j++){
         if(v[j] != 0){
            int floor_ex =  j/i;
            if ( j % i !=0)floor_ex ++;
            //cout << "floor" << i << "  ex    " << floor_ex << "flat  "<< j<< endl;
            //cout << floor_ex <<" "<<v[j] << endl;
            if(floor_ex != v[j]){
               contr = true;
               break;
            }
         }
      }
      if(!contr) {
         way++;
         int old_save = save;
         save = N/i;
         if (N % i != 0)save++;
         if( save == old_save)way--;
      }
   }

   if(way == 1) cout << save;
   else cout << "-1";
   return 0;
}


//
//  main.cpp
//  A
//
//  Created by Eleonora Rocchi on 17/09/17.
//  Copyright © 2017 Eleonora Rocchi. All rights reserved.
//

#include <iostream>
#include <stdio.h>
using namespace std;
int v[1000];
int N, M, start = 1;
int main() {
   cin >> N >> M;
   int x,y;
   for(int i =0; i < M; i++){
      cin >> x >> y;
      v[x] = y;
   }
   int way = 0,save = 1000;
   for(int i = 1; i <= N; i++){
      bool contr = false;
      for(int j = 1; j <= N; j++){
         if(v[j] != 0){
            int floor_ex =  j/i;
            if ( j % i !=0)floor_ex ++;
            //cout << "floor" << i << "  ex    " << floor_ex << "flat  "<< j<< endl;
            //cout << floor_ex <<" "<<v[j] << endl;
            if(floor_ex != v[j]){
               contr = true;
               break;
            }
         }
      }
      if(!contr) {
         way++;
         int old_save = save;
         save = N/i;
         if (N % i != 0)save++;
         if( save == old_save)way--;
      }
   }

   if(way == 1) cout << save;
   else cout << "-1";
   return 0;
}


//
//  main.cpp
//  A
//
//  Created by Eleonora Rocchi on 17/09/17.
//  Copyright © 2017 Eleonora Rocchi. All rights reserved.
//

#include <iostream>
#include <stdio.h>
using namespace std;
int v[1000];
int N, M, start = 1;
int main() {
   cin >> N >> M;
   int x,y;
   for(int i =0; i < M; i++){
      cin >> x >> y;
      v[x] = y;
   }
   int way = 0,save = 1000;
   for(int i = 1; i <= N; i++){
      bool contr = false;
      for(int j = 1; j <= 100; j++){
         if(v[j] != 0){
            int floor_ex =  j/i;
            if ( j % i !=0)floor_ex ++;
            //cout << "floor" << i << "  ex    " << floor_ex << "flat  "<< j<< endl;
            //cout << floor_ex <<" "<<v[j] << endl;
            if(floor_ex != v[j]){
               contr = true;
               break;
            }
         }
      }
      if(!contr) {
         way++;
         int old_save = save;
         save = N/i;
         if (N % i != 0)save++;
         if( save == old_save)way--;
      }
   }

   if(way == 1) cout << save;
   else cout << "-1";
   return 0;
}


//
//  main.cpp
//  A
//
//  Created by Eleonora Rocchi on 17/09/17.
//  Copyright © 2017 Eleonora Rocchi. All rights reserved.
//

#include <iostream>
#include <stdio.h>
using namespace std;
int v[1000];
int N, M, start = 1;
int main() {
   cin >> N >> M;
   int x,y;
   for(int i =0; i < M; i++){
      cin >> x >> y;
      v[x] = y;
   }
   int way = 0,save = 1000;
   for(int i = 1; i <= 100; i++){
      bool contr = false;
      for(int j = 1; j <= 100; j++){
         if(v[j] != 0){
            int floor_ex =  j/i;
            if ( j % i !=0)floor_ex ++;
            //cout << "floor" << i << "  ex    " << floor_ex << "flat  "<< j<< endl;
            //cout << floor_ex <<" "<<v[j] << endl;
            if(floor_ex != v[j]){
               contr = true;
               break;
            }
         }
      }
      if(!contr) {
         way++;
         int old_save = save;
         save = N/i;
         if (N % i != 0)save++;
         if( save == old_save)way--;
      }
   }

   if(way == 1) cout << save;
   else cout << "-1";
   return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cmath>

using namespace std;

int main() {
	// your code goes here
	int n,m,a,b,ar[293],br[293],k,t = 1000,p=-1,q=1;
	cin>>n>>m;
	for (int i = 0; i < 200; i++){
		ar[i] = 0;
		br[i] = 300;

	}
	for (int i = 0; i <m; i++){
		cin>>a>>b;
		ar[b] = max(ar[b],a);
		br[b] = min(br[b],a);
		k = max(k,b);
	}
	for (int i = 1; i <= k; i++){
		if (n > ar[i]) q = i;
		if (n >= ar[i] && n <= br[i]) {cout<<i; return 0;}
		if (ar[i] < br[i+1]) t = min (br[i+1] - ar[i] , t);
		if  (t == 1) {
			t = ar[i] / i;
			if (n % t > 0) t++;
			cout<<t;
			return 0;
		}
	}
	if (br[k] + t>= n)
	cout<<k; else cout<<p;
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	// your code goes here
	  int n,m,a[123],b[123];
    cin>>n>>m;
    for (int i = 1; i <= m; ++i)
       cin>>a[i]>>b[i];

    int ans = -1;
    int t = 0;
    for (int i = 1; i <= 100; ++i)
    {
        bool flag = 1;
        for (int j = 1; j <= m; ++j)
        {
            if ((a[j] + i - 1) / i != b[j])
            {
                flag = 0;
                break;
            }
        }
        if (flag)
        {

            if (ans == -1)
                ans = (n + i - 1) / i;
            else
            {
                if ((n + i - 1) / i != ans)
                {
                    t = 1;
                    break;
                }

            }
        }
    }

    if (t == 1)
        cout << -1 << endl;
    else
        cout << ans << endl;

	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cmath>

using namespace std;

int main() {
	// your code goes here
	int n,m,a,b,ar[293],br[293],k,t = 0,p=0,w=0,q=0,ww=1000;
	cin>>n>>m;
	for (int i = 0; i < 200; i++){
		ar[i] = 0;
		br[i] = 300;

	}
	for (int i = 0; i <m; i++){
		cin>>a>>b;
		ar[a] = b;
	}
		for (int i = 1; i <= 101; i++)
		{
		t = 1;
		for (int j = 1; j <= 101; j++){
			br[j] = t;
			if (j >= i && j % i == 0) t++;
		}
		q = 0;
		for (int j = 1; j <= 101; j++){
			if (ar[j] > 0 && ar[j] != br[j]) q=1;
			br[j] =0;
		}
		if (q == 0 && ww!=w) {p++;w = i;ww = min(ww,i); }
		}
		if (p == 1) {
			if ( n% w > 0 ) cout<<(n/w) + 1; else cout<<n/w;
		return 0;
		}
		cout<<-1 ;
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cmath>

using namespace std;

int main() {
	// your code goes here
	int n,m,a,b,ar[293],k,t = 1,p=-1;
	cin>>n>>m;
	k = n;
	for (int i = 0; i < 200; i++)
		ar[i] = 0;
	for (int i = 0; i <m; i++){
		cin>>a>>b;
		ar[a] = b;
		k = max(k,a);
	}
	for (int i = 1; i <= k; i++){
		if (ar[i] + 1 == ar[i+1] && ar[i] > 0) {
			p = n / (i / ar[i]);
			if (n % (i / ar[i]) > 0) p++;
			cout<<p;
			return 0;
		}
	}
	cout<<p;
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <cmath>

using namespace std;

int main() {
	// your code goes here
	int n,m,a,b,ar[293],br[293],k,t = 1000,p=-1,q=1;
	cin>>n>>m;
	for (int i = 0; i < 200; i++){
		ar[i] = 0;
		br[i] = 300;

	}
	for (int i = 0; i <m; i++){
		cin>>a>>b;
		ar[b] = max(ar[b],a);
		br[b] = min(br[b],a);
		k = max(k,b);
	}
	for (int i = 1; i <= k; i++){
		if (n > ar[i]) q = i;
		if (n <= ar[i] && n >= br[i]) {cout<<i; return 0;}
		if (ar[i] < br[i+1]) t = min (br[i+1] - ar[i] , t);
		if  (t == 1) {
			t = ar[i] / i;
			if (n % t > 0) t++;
			cout<<t;
			return 0;
		}
	}
	if (br[k] + t>= n)
	cout<<k; else cout<<p;
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 5;

int n,m,f[maxn],k[maxn];

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

int main()
{
	scanf("%d %d",&n,&m);
	int mx = 0;
	for (int i = 1;i <= m;i++)
	{
		scanf("%d %d",&k[i],&f[i]);

		if (k[i] - 1 != 0)
		{
			int x = (f[i] - 1) % (k[i] - 1);
			if ((f[i] - 1) % (k[i] - 1)) x++;
			mx = max(mx,x);
		}

	}

	if (m == 0 || mx == 0) {printf("1");return 0;}

	int flag = 0;
	for (int i = 1;i <= mx;i++)
	{
		if (ok(i)) {flag = i;break;}
	}
	if (flag == 0) puts("-1");
	else
	{
		int ans = n / flag;
		if (n % flag) ans++;
		printf("%d\n",ans);
	}

	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 5;

int n,m,f[maxn],k[maxn];

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

int main()
{
	scanf("%d %d",&n,&m);
	int mx = 0;
	for (int i = 1;i <= m;i++)
	{
		scanf("%d %d",&k[i],&f[i]);
		int x = (f[i] - 1) % (k[i] - 1);
		if ((f[i] - 1) % (k[i] - 1)) x++;
		mx = max(mx,x);
	}

	int flag = 0;
	for (int i = 1;i <= mx;i++)
	{
		if (ok(i)) {flag = i;break;}
	}
	if (flag == 0) puts("-1");
	else
	{
		int ans = n / flag;
		if (n % flag) ans++;
		printf("%d\n",ans);
	}

	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 5;

int n,m,f[maxn],k[maxn];

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

int main()
{
	scanf("%d %d",&n,&m);
	for (int i = 1;i <= m;i++)
	{
		scanf("%d %d",&k[i],&f[i]);

	}

	if (n == 1) {puts("1");return 0;}
	if (m == 0) {printf("-1");return 0;}

	vector<int> ans;
	for (int i = 1;i <= 100;i++)
	{
		if (ok(i)) {ans.push_back(i);}
	}

	if (ans.size() != 1) puts("-1");
	else
	{
		int res = n / ans[0];
		if (n % ans[0]) res++;
		printf("%d\n",res);
	}

	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 5;

int n,m,f[maxn],k[maxn];

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

int main()
{
	scanf("%d %d",&n,&m);
	for (int i = 1;i <= m;i++)
	{
		scanf("%d %d",&k[i],&f[i]);

	}

	if (m == 0 && n != 1) {printf("-1");return 0;}
	if (m == 0 && n == 1) {printf("1");return 0;}

	vector<int> ans;
	for (int i = 1;i <= 100;i++)
	{
		if (ok(i)) {ans.push_back(i);}
	}

	if (ans.size() != 1) puts("-1");
	else
	{
		int res = n / ans[0];
		if (n % ans[0]) res++;
		printf("%d\n",res);
	}

	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 5;

int n,m,f[maxn],k[maxn];

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

int main()
{
	scanf("%d %d",&n,&m);
	for (int i = 1;i <= m;i++)
	{
		scanf("%d %d",&k[i],&f[i]);
	}

	if (n == 1) {puts("1");return 0;}
	if (m == 0) {printf("-1");return 0;}

	vector<int> ans;
	for (int i = 1;i <= 100;i++)
	{
		if (ok(i)) {ans.push_back(i);}
	}

	set<int> res;
	for (int i = 0;i < ans.size();i++)
	{
		int now = (n - 1) / ans[i] + 1;
		res.insert(now);
	}
	if (res.size() != 1) puts("-1");
	else
	{
		set<int>::iterator it = res.begin();
		printf("%d\n",*it);
	}

	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 5;

int n,m,f[maxn],k[maxn];

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

int main()
{
	scanf("%d %d",&n,&m);
	int mx = 0;
	for (int i = 1;i <= m;i++)
	{
		scanf("%d %d",&k[i],&f[i]);

	}

	if (m == 0) {printf("1");return 0;}

	vector<int> ans;
	for (int i = 1;i <= 10000;i++)
	{
		if (ok(i)) {ans.push_back(i);}
	}
	if (ans.size() != 1) puts("-1");
	else
	{
		//printf("flag = %d\n",flag);
		int res = n / ans[0];
		if (n % ans[0]) res++;
		printf("%d\n",res);
	}

	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 5;

int n,m,f[maxn],k[maxn];

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

int main()
{
	scanf("%d %d",&n,&m);
	for (int i = 1;i <= m;i++)
	{
		scanf("%d %d",&k[i],&f[i]);

	}

	if (m == 0) {printf("-1");return 0;}

	vector<int> ans;
	for (int i = 1;i <= 10000;i++)
	{
		if (ok(i)) {ans.push_back(i);}
	}

	//for (int i = 0;i < ans.size();i++) printf("ans[%d] = %d\n",i,ans[i]);

	if (ans.size() != 1) puts("-1");
	else
	{
		//printf("flag = %d\n",flag);
		int res = n / ans[0];
		if (n % ans[0]) res++;
		printf("%d\n",res);
	}

	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 5;

int n,m,f[maxn],k[maxn];

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

int main()
{
	scanf("%d %d",&n,&m);
	for (int i = 1;i <= m;i++)
	{
		scanf("%d %d",&k[i],&f[i]);

	}

	if (n == 1) {puts("1");return 0;}
	if (m == 0) {printf("-1");return 0;}

	vector<int> ans;
	for (int i = 1;i <= 100;i++)
	{
		if (ok(i)) {ans.push_back(i);}
	}

	if (ans.size() != 1) puts("-1");
	else
	{
		int res = (n - 1) / ans[0] + 1;
		printf("%d\n",res);
	}

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <queue>
#include <string>

namespace {
	using number_t = long long;
}

int main() {
	int N, M;
	std::cin >> N >> M;
	std::vector<std::pair<int, int>> mem(M);
	int max = N;
	for (auto& el : mem) {
		std::cin >> el.first >> el.second;
		max = std::max(N, el.first);
		--el.first;
		--el.second;
	}
	int mod = -1;
	for (int i = 1 ; i <= max ; ++i) {
		bool OK = true;
		for (auto el : mem) {
			if (el.first / i != el.second) {
				OK = false;
				break;
			}
		}
		if (OK) {
			if (mod != -1) {
				std::cout << -1 << std::endl;
				return 0;
			}
			mod = i;
		}
	}
	if (mod != -1) {
		--N;
		std::cout << N / mod + 1<< std::endl;
	} else {
		std::cout << -1 << std::endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <queue>
#include <string>

namespace {
	using number_t = long long;
}

int main() {
	int N, M;
	std::cin >> N >> M;
	std::vector<std::pair<int, int>> mem(M);
	int max = N;
	for (auto& el : mem) {
		std::cin >> el.first >> el.second;
		max = std::max(N, el.first);
		--el.first;
	}
	int mod = -1;
	for (int i = 1 ; i <= max ; ++i) {
		bool OK = true;
		for (auto el : mem) {
			if (el.first / i + 1 != el.second) {
				OK = false;
				break;
			}
		}
		if (OK) {
			if (mod != -1) {
				std::cout << -1 << std::endl;
				return 0;
			}
			mod = i;
		}
	}
	if (mod != -1) {
		std::cout << N / mod + 1<< std::endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <queue>
#include <string>

namespace {
	using number_t = long long;
}

int main() {
	int N, M;
	std::cin >> N >> M;
	std::vector<std::pair<int, int>> mem(M);
	int max = N;
	int max_floor = 0;
	for (auto& el : mem) {
		std::cin >> el.first >> el.second;
		max = std::max(max, el.first);
		--el.first;
		--el.second;
		max_floor = std::max(max_floor, el.second);
	}
	std::vector<int> mods;
	for (int i = 1 ; i <= max ; ++i) {
		bool OK = true;
		for (auto el : mem) {
			if (el.first / i != el.second) {
				OK = false;
				break;
			}
		}
		if (OK) {
			mods.push_back(i);
		}
	}
	if (!mods.empty()) {
		--N;
		int floor = N / mods[0];
		for (size_t i = 1 ; i < mods.size() ; ++i) {
			if (N / mods[i] != floor) {
				std::cout << -1 << std::endl;
				return 0;
			}
		}
		std::cout << floor + 1 << std::endl;
	} else {
		std::cout << -1 << std::endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <queue>
#include <string>

namespace {
	using number_t = long long;
}

int main() {
	int N, M;
	std::cin >> N >> M;
	std::vector<std::pair<int, int>> mem(M);
	int max = N;
	for (auto& el : mem) {
		std::cin >> el.first >> el.second;
		max = std::max(N, el.first);
		--el.first;
	}
	int mod = -1;
	for (int i = 1 ; i <= max ; ++i) {
		bool OK = true;
		for (auto el : mem) {
			if (el.first / i + 1 != el.second) {
				OK = false;
				break;
			}
		}
		if (OK) {
			if (mod != -1) {
				std::cout << -1 << std::endl;
				return 0;
			}
			mod = i;
		}
	}
	if (mod != -1) {
		--N;
		std::cout << N / mod + 1<< std::endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <queue>
#include <string>

namespace {
	using number_t = long long;
}

int main() {
	int N, M;
	std::cin >> N >> M;
	std::vector<std::pair<int, int>> mem(M);
	int max = N;
	int max_floor = 0;
	for (auto& el : mem) {
		std::cin >> el.first >> el.second;
		max = std::max(max, el.first);
		--el.first;
		--el.second;
		max_floor = std::max(max_floor, el.second);
	}
	int mod = -1;
	for (int i = 1 ; i <= max && !mem.empty() && max_floor > 0 ; ++i) {
		bool OK = true;
		for (auto el : mem) {
			if (el.first / i != el.second) {
				OK = false;
				break;
			}
		}
		if (OK) {
			if (mod != -1) {
				std::cout << -1 << std::endl;
				return 0;
			}
			mod = i;
		}
	}
	if (mod != -1 && mod != max) {
		--N;
		std::cout << N / mod + 1 << std::endl;
	} else {
		std::cout << -1 << std::endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <queue>
#include <string>

namespace {
	using number_t = long long;
}

int main() {
	int N, M;
	std::cin >> N >> M;
	std::vector<std::pair<int, int>> mem(M);
	int max = N;
	for (auto& el : mem) {
		std::cin >> el.first >> el.second;
		max = std::max(max, el.first);
		--el.first;
		--el.second;
	}
	int mod = -1;
	for (int i = 1 ; i <= max && !mem.empty() ; ++i) {
		bool OK = true;
		for (auto el : mem) {
			if (el.first / i != el.second) {
				OK = false;
				break;
			}
		}
		if (OK) {
			if (mod != -1) {
				std::cout << -1 << std::endl;
				return 0;
			}
			mod = i;
		}
	}
	if (mod != -1) {
		--N;
		std::cout << N / mod + 1 << std::endl;
	} else {
		std::cout << -1 << std::endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <queue>
#include <string>

namespace {
	using number_t = long long;
}

int main() {
	int N, M;
	std::cin >> N >> M;
	std::vector<std::pair<int, int>> mem(M);
	int max = N;
	int max_floor = 0;
	for (auto& el : mem) {
		std::cin >> el.first >> el.second;
		max = std::max(max, el.first);
		--el.first;
		--el.second;
		max_floor = std::max(max_floor, el.second);
	}
	std::vector<int> mods;
	for (int i = 1 ; i <= max && !mem.empty() && max_floor > 0 ; ++i) {
		bool OK = true;
		for (auto el : mem) {
			if (el.first / i != el.second) {
				OK = false;
				break;
			}
		}
		if (OK) {
			mods.push_back(i);
		}
	}
	if (!mods.empty()) {
		--N;
		int floor = N / mods[0];
		for (size_t i = 1 ; i < mods.size() ; ++i) {
			if (N / mods[i] != floor) {
				std::cout << -1 << std::endl;
				return 0;
			}
		}
		std::cout << floor + 1 << std::endl;
	} else {
		std::cout << -1 << std::endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <queue>
#include <string>

namespace {
	using number_t = long long;
}

int main() {
	int N, M;
	std::cin >> N >> M;
	std::vector<std::pair<int, int>> mem(M);
	int max = N;
	for (auto& el : mem) {
		std::cin >> el.first >> el.second;
		max = std::max(max, el.first);
		--el.first;
		--el.second;
	}
	int mod = -1;
	for (int i = 1 ; i <= max ; ++i) {
		bool OK = true;
		for (auto el : mem) {
			if (el.first / i != el.second) {
				OK = false;
				break;
			}
		}
		if (OK) {
			if (mod != -1) {
				std::cout << -1 << std::endl;
				return 0;
			}
			mod = i;
		}
	}
	if (mod != -1) {
		--N;
		std::cout << N / mod + 1<< std::endl;
	} else {
		std::cout << -1 << std::endl;
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <queue>
#include <string>

namespace {
	using number_t = long long;
}

int main() {
	int N, M;
	std::cin >> N >> M;
	std::vector<std::pair<int, int>> mem(M);
	int max = N;
	for (auto& el : mem) {
		std::cin >> el.first >> el.second;
		max = std::max(max, el.first);
		--el.first;
		--el.second;
	}
	int mod = -1;
	for (int i = 1 ; i <= max && !mem.empty() ; ++i) {
		bool OK = true;
		for (auto el : mem) {
			if (el.first / i != el.second) {
				OK = false;
				break;
			}
		}
		if (OK) {
			if (mod != -1) {
				std::cout << -1 << std::endl;
				return 0;
			}
			mod = i;
		}
	}
	if (mod != -1 && mod != max) {
		--N;
		std::cout << N / mod + 1 << std::endl;
	} else {
		std::cout << -1 << std::endl;
	}
	return 0;
}


#include <iostream>
#include <fstream>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

#define fi "baib.inp"
#define fo "baib.out"

int n,m;
int a[110],b[110];

void solve()
{
    int i,sln,snn,k,f;

    for (i=0; i<m; i++){
        scanf("%d %d", &k, &f);
        if (f == 1)
            a[i] = 100;
        else
            a[i] = (k-1)/(f-1);
        if (k % f == 0)
            b[i] = k/f;
        else
            b[i] = k/f + 1;
    }
    snn = 101;
    sln = 0;

    for (i=0; i<m; i++){
        if (snn > a[i])
            snn = a[i];
        if (sln < b[i])
            sln  = b[i];
    }

    if (snn == sln){
        if (n % snn == 0)
            printf("%d\n",n/snn);
        else
            printf("%d\n",(n/snn)+1);
    }
    else
        printf("-1\n");
}

int main()
{
//    freopen(fi,"r",stdin);
 //   freopen(fo,"w",stdout);

    while (scanf("%d %d", &n, &m) > 0){
        solve();
    }

    return 0;
}


#include <iostream>
#include <fstream>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

#define fi "baib.inp"
#define fo "baib.out"

int n,m;
int a[110],b[110];

void solve()
{
    int i,sln,snn,k,f,kq1,kq2;

    for (i=0; i<m; i++){
        scanf("%d %d", &k, &f);
        if (f == 1)
            a[i] = 100;
        else
            a[i] = (k-1)/(f-1);
        if (k % f == 0)
            b[i] = k/f;
        else
            b[i] = k/f + 1;
    }

    snn = 101;
    sln = 0;

    for (i=0; i<m; i++){
        if (snn > a[i])
            snn = a[i];
        if (sln < b[i])
            sln  = b[i];
    }
    kq1 = n/snn + min(1,n%snn);
    kq2 = n/sln + min(1,n%sln);
    if (kq1 == kq2)
        printf("%d\n",kq1);
    else
        printf("-1\n");
}

int main()
{
 //   freopen(fi,"r",stdin);
 //   freopen(fo,"w",stdout);

    while (scanf("%d %d", &n, &m) > 0){
        solve();
    }

    return 0;
}


#include <iostream>
#include <fstream>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

#define fi "baib.inp"
#define fo "baib.out"

int n,m;
int a[110],b[110];

void solve()
{
    int i,sln,snn,k,f,kq1,kq2;

    for (i=0; i<m; i++){
        scanf("%d %d", &k, &f);
        if (f == 1)
            a[i] = 100;
        else
            a[i] = (k-1)/(f-1);
        if (k % f == 0)
            b[i] = k/f;
        else
            b[i] = k/f + 1;
    }

    if (n == 1){
        printf("1\n");
        return;
    }

    snn = 101;
    sln = 1;

    for (i=0; i<m; i++){
        if (snn > a[i])
            snn = a[i];
        if (sln < b[i])
            sln  = b[i];
    }
    kq1 = n/snn + min(1,n%snn);
    kq2 = n/sln + min(1,n%sln);
    if (kq1 == kq2)
        printf("%d\n",kq1);
    else
        printf("-1\n");
}

int main()
{
//    freopen(fi,"r",stdin);
//    freopen(fo,"w",stdout);

    while (scanf("%d %d", &n, &m) > 0){
        solve();
    }

    return 0;
}


#include <iostream>
#include <fstream>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

#define fi "baib.inp"
#define fo "baib.out"

int n,m;
int d[110];

void solve()
{
    int i,sl,k,f;

    for (i=1; i<=100; i++)
        d[i] = 0;
    for (i=0; i<m; i++){
        scanf("%d %d", &k, &f);
        d[k] = f;
    }

    for (i=1; i<100; i++){
        if ((d[i] != d[i+1] && d[i] != 0 && d[i+1] != 0) || (d[n] != 0)){
            sl = i/d[i];
            if (n % sl == 0)
                printf("%d\n",n/sl);
            else
                printf("%d\n",n/sl+1);
            return;
        }
    }

    printf("-1\n");
}

int main()
{
//    freopen(fi,"r",stdin);
//    freopen(fo,"w",stdout);

    while (scanf("%d %d", &n, &m) > 0){
        solve();
    }

    return 0;
}


#include <iostream>
#include <fstream>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

#define fi "baib.inp"
#define fo "baib.out"

int n,m;
int a[110],b[110];

void solve()
{
    int i,sln,snn,k,f,kq1,kq2;

    if (n == 1){
        printf("1\n");
        return;
    }

    for (i=0; i<m; i++){
        scanf("%d %d", &k, &f);
        if (f == 1)
            a[i] = 100;
        else
            a[i] = (k-1)/(f-1);
        if (k % f == 0)
            b[i] = k/f;
        else
            b[i] = k/f + 1;
    }
    snn = 101;
    sln = 0;

    for (i=0; i<m; i++){
        if (snn > a[i])
            snn = a[i];
        if (sln < b[i])
            sln  = b[i];
    }
    kq1 = n/snn + min(1,n%snn);
    kq2 = n/sln + min(1,n%sln);
    if (kq1 == kq2)
        printf("%d\n",kq1);
    else
        printf("-1\n");
}

int main()
{
//    freopen(fi,"r",stdin);
//    freopen(fo,"w",stdout);

    while (scanf("%d %d", &n, &m) > 0){
        solve();
    }

    return 0;
}


#include <iostream>
#include <fstream>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

#define fi "baib.inp"
#define fo "baib.out"

int n,m;
int a[110],b[110];

void solve()
{
    int i,sln,snn,k,f,kq1,kq2;

    for (i=0; i<m; i++){
        scanf("%d %d", &k, &f);
        if (f == 1)
            a[i] = 100;
        else
            a[i] = (k-1)/(f-1);
        if (k % f == 0)
            b[i] = k/f;
        else
            b[i] = k/f + 1;
    }

    if (n == 1){
        printf("1\n");
        return;
    }

    snn = 101;
    sln = 0;

    for (i=0; i<m; i++){
        if (snn > a[i])
            snn = a[i];
        if (sln < b[i])
            sln  = b[i];
    }
    kq1 = n/snn + min(1,n%snn);
    kq2 = n/sln + min(1,n%sln);
    if (kq1 == kq2)
        printf("%d\n",kq1);
    else
        printf("-1\n");
}

int main()
{
//    freopen(fi,"r",stdin);
//    freopen(fo,"w",stdout);

    while (scanf("%d %d", &n, &m) > 0){
        solve();
    }

    return 0;
}


#include <iostream>
#include <fstream>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

#define fi "baib.inp"
#define fo "baib.out"

int n,m;
int a[110],b[110];

void solve()
{
    int i,sln,snn,k,f;

    if (n == 1){
        printf("1\n");
        return;
    }

    for (i=0; i<m; i++){
        scanf("%d %d", &k, &f);
        if (f == 1)
            a[i] = 100;
        else
            a[i] = (k-1)/(f-1);
        if (k % f == 0)
            b[i] = k/f;
        else
            b[i] = k/f + 1;
    }
    snn = 101;
    sln = 0;

    for (i=0; i<m; i++){
        if (snn > a[i])
            snn = a[i];
        if (sln < b[i])
            sln  = b[i];
    }

    if (snn == sln){
        if (n % snn == 0)
            printf("%d\n",n/snn);
        else
            printf("%d\n",(n/snn)+1);
    }
    else
        printf("-1\n");
}

int main()
{
//    freopen(fi,"r",stdin);
 //   freopen(fo,"w",stdout);

    while (scanf("%d %d", &n, &m) > 0){
        solve();
    }

    return 0;
}


#include <iostream>
#include <fstream>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

#define fi "baib.inp"
#define fo "baib.out"

int n,m;
int d[110];

void solve()
{
    int i,sl,k,f;

    for (i=1; i<=100; i++)
        d[i] = 0;
    for (i=0; i<m; i++){
        scanf("%d %d", &k, &f);
        d[k] = f;
    }

    for (i=1; i<100; i++){
        if (d[i] != d[i+1] && d[i] != 0 && d[i+1] != 0){
            sl = i/d[i];
            if (n % sl == 0)
                printf("%d\n",n/sl);
            else
                printf("%d\n",n/sl+1);
            return;
        }
    }

    printf("-1\n");
}

int main()
{
//    freopen(fi,"r",stdin);
//    freopen(fo,"w",stdout);

    while (scanf("%d %d", &n, &m) > 0){
        solve();
    }

    return 0;
}


#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MIN(Y)  Y##_MIN // Y = {SCHAR, CHAR, SHRT, INT, LONG, LLONG}
#define MAX(X)  X##_MAX // X = Y U {UCHAR, USHRT, UINT, ULONG, ULLONG}

using namespace std;

int main (void)
{
  IOS

  int n, m, nf = 0;
  vector<pair<int,int>> f;

  cin>>n>>m;

  n--;

  for (int i=0; i<m; i++)
  {
    int a ,b;
    cin>>a>>b;
    a--;
    b--;
    f.push_back (make_pair (a, b));
  }

  for (int i=1, pc = 0; i<=100; i++)
  {
    bool poss = true;

    for (pair<int,int> p : f)
    {
      if (p.first/i != p.second)
      {
        poss = false;
        break;
      }
    }

    if (poss)
    {
      if (pc == 1)
      {
        cout<<-1<<endl;
        return 0;
      }
      nf = i;
      pc = 1;
    }
  }

  cout<<(nf?(n/nf+1):-1)<<endl;

  return 0;
}


#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MIN(Y)  Y##_MIN // Y = {SCHAR, CHAR, SHRT, INT, LONG, LLONG}
#define MAX(X)  X##_MAX // X = Y U {UCHAR, USHRT, UINT, ULONG, ULLONG}

using namespace std;

bool comp (pair<int,int> &a, pair<int,int> &b)
{
  return a.first < b.first;
}

int main (void)
{
  IOS

  int n, m, nf = 0;
  vector<pair<int,int>> f;

  cin>>n>>m;

  n--;

  for (int i=0; i<m; i++)
  {
    int a ,b;
    cin>>a>>b;

    a--;
    b--;

    if (n==a)
    {
      cout<<b+1<<endl;
      return 0;
    }

    f.push_back (make_pair (a, b));
  }

  sort (f.begin, f.end (), comp)

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

  for (int i=1, pc = 0; i<=200; i++)
  {
    bool poss = true;

    for (pair<int,int> p : f)
    {
      if (p.first/i != p.second)
      {
        poss = false;
        break;
      }
    }

    if (poss)
    {
      if (pc == 1)
      {
        cout<<-1<<endl;
        return 0;
      }
      nf = i;
      pc = 1;
    }
  }

  cout<<(nf?(n/nf+1):-1)<<endl;

  return 0;
}


#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MIN(Y)  Y##_MIN // Y = {SCHAR, CHAR, SHRT, INT, LONG, LLONG}
#define MAX(X)  X##_MAX // X = Y U {UCHAR, USHRT, UINT, ULONG, ULLONG}

using namespace std;

int main (void)
{
  IOS

  int n, m, nf = 0;
  vector<pair<int,int>> f;

  cin>>n>>m;

  n--;

  for (int i=0; i<m; i++)
  {
    int a ,b;
    cin>>a>>b;

    a--;
    b--;

    if (n==a)
    {
      cout<<b+1<<endl;
      return 0;
    }

    f.push_back (make_pair (a, b));
  }

  for (int i=1, pc = 0; i<=200; i++)
  {
    bool poss = true;

    for (pair<int,int> p : f)
    {
      if (p.first/i != p.second)
      {
        poss = false;
        break;
      }
    }

    if (poss)
    {
      if (pc == 1)
      {
        cout<<-1<<endl;
        return 0;
      }
      nf = i;
      pc = 1;
    }
  }

  cout<<(nf?(n/nf+1):-1)<<endl;

  return 0;
}


#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MIN(Y)  Y##_MIN // Y = {SCHAR, CHAR, SHRT, INT, LONG, LLONG}
#define MAX(X)  X##_MAX // X = Y U {UCHAR, USHRT, UINT, ULONG, ULLONG}

using namespace std;

int main (void)
{
  IOS

  int n, m, nf = 0;
  vector<pair<int,int>> f;

  cin>>n>>m;

  n--;

  for (int i=0; i<m; i++)
  {
    int a ,b;
    cin>>a>>b;
    a--;
    b--;
    f.push_back (make_pair (a, b));
  }

  for (int i=1, pc = 0; i<=200; i++)
  {
    bool poss = true;

    for (pair<int,int> p : f)
    {
      if (p.first/i != p.second)
      {
        poss = false;
        break;
      }
    }

    if (poss)
    {
      if (pc == 1)
      {
        cout<<-1<<endl;
        return 0;
      }
      nf = i;
      pc = 1;
    }
  }

  cout<<(nf?(n/nf+1):-1)<<endl;

  return 0;
}


#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MIN(Y)  Y##_MIN // Y = {SCHAR, CHAR, SHRT, INT, LONG, LLONG}
#define MAX(X)  X##_MAX // X = Y U {UCHAR, USHRT, UINT, ULONG, ULLONG}

using namespace std;

bool comp (pair<int,int> &a, pair<int,int> &b)
{
  return a.first < b.first;
}

int main (void)
{
  IOS

  int n, m, nf = 0;
  vector<pair<int,int>> f;

  cin>>n>>m;

  n--;

  for (int i=0; i<m; i++)
  {
    int a ,b;
    cin>>a>>b;

    a--;
    b--;

    if (n==a)
    {
      cout<<b+1<<endl;
      return 0;
    }

    f.push_back (make_pair (a, b));
  }

  sort (f.begin (), f.end (), comp);

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

  for (int i=1, pc = 0; i<=200; i++)
  {
    bool poss = true;

    for (pair<int,int> p : f)
    {
      if (p.first/i != p.second)
      {
        poss = false;
        break;
      }
    }

    if (poss)
    {
      if (nf !=0 &&  nf != (n/i+1))
      {
        cout<<-1<<endl;
        return 0;
      }
      nf = (n/i+1);
    }
  }

  cout<<nf<<endl;

  return 0;
}


#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MIN(Y)  Y##_MIN // Y = {SCHAR, CHAR, SHRT, INT, LONG, LLONG}
#define MAX(X)  X##_MAX // X = Y U {UCHAR, USHRT, UINT, ULONG, ULLONG}

using namespace std;

bool comp (pair<int,int> &a, pair<int,int> &b)
{
  return a.first < b.first;
}

int main (void)
{
  IOS

  int n, m, nf = 0;
  vector<pair<int,int>> f;

  cin>>n>>m;

  n--;

  for (int i=0; i<m; i++)
  {
    int a ,b;
    cin>>a>>b;

    a--;
    b--;

    if (n==a)
    {
      cout<<b+1<<endl;
      return 0;
    }

    f.push_back (make_pair (a, b));
  }

  sort (f.begin (), f.end (), comp);

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

  for (int i=1, pc = 0; i<=200; i++)
  {
    bool poss = true;

    for (pair<int,int> p : f)
    {
      if (p.first/i != p.second)
      {
        poss = false;
        break;
      }
    }

    if (poss)
    {
      if (pc == 1)
      {
        cout<<-1<<endl;
        return 0;
      }
      nf = i;
      pc = 1;
    }
  }

  cout<<(nf?(n/nf+1):-1)<<endl;

  return 0;
}


///        +====================+
///        "In The Name Of Allah"
///    +----+------------------+----+
///    |2017| Ali Mollahoseini |1396|
///    | 09 +------------------+ 06 |
///    | 17 |   CF Round 434   | 26 |
///    +----+------------------+----+

#include <bits/stdc++.h>
#define ll long long
#define int long long
#define F first
#define S second
#define pb push_back
#define Init ios::sync_with_stdio(0),cin.tie(0);

const int MX = 2000 + 1000, inf = 0x7FFFFFFF, mod = 1000 * 1000 * 1000 + 7;
using namespace std;
int n , m;
pair<int,int> inp[MX];
bool ok(int l ,int r,int x){
    if(l<=x && x<r){
        return 1;
    }
    return 0;
}
int32_t main(){
    Init
    cin>>n>>m;
    n--;
    for(int i=0;i<m;i++){
        cin>>inp[i].F>>inp[i].S;
        inp[i].F--;
        if(inp[i].F==n){
            cout<<inp[i].S<<endl;
            return 0;
        }
    }
    sort(inp,inp+m);
    int cnt=0;
    int ind;
    for(int i=1;i<102;i++){
        bool is=1;
        for(int j=0;j<m;j++){
            /*
            if(i==3){
                cout<<inp[j].F<<' '<<inp[j].S<<' '<<inp[j].S*(i-1)<<' '<<inp[j].S*(i)<<' '<<ok(inp[j].S*(i-1),inp[j].S*(i),inp[j].F)<<endl;
            }
            */
            if(!ok((inp[j].S-1)*i,(inp[j].S)*(i),inp[j].F)){
                is=0;
            }
        }
        if(is){
            if(!cnt){
                ind = (n/i)+1;
            }
            cnt++;
        }
    }
    if(cnt==1){
        cout<<ind;
    }else if(n>inp[m-1].F){
        cout<<-1;
    }else{
        int cur =0;
        int floor=1;
        for(int i=0;i<n;i++){
            if(cur<=n && n<inp[i].F &&inp[i].S==floor){
                cout<<floor<<endl;
                return 0;
            }else{
                cur = inp[i].F;
                floor = inp[i].S;
            }
        }
        cout<<-1<<endl;
    }
}


///        +====================+
///        "In The Name Of Allah"
///    +----+------------------+----+
///    |2017| Ali Mollahoseini |1396|
///    | 09 +------------------+ 06 |
///    | 17 |   CF Round 434   | 26 |
///    +----+------------------+----+

#include <bits/stdc++.h>
#define ll long long
#define int long long
#define F first
#define S second
#define pb push_back
#define Init ios::sync_with_stdio(0),cin.tie(0);

const int MX = 2000 + 1000, inf = 0x7FFFFFFF, mod = 1000 * 1000 * 1000 + 7;
using namespace std;
int n , m;
pair<int,int> inp[MX];
bool ok(int l ,int r,int x){
    if(l<=x &&x<r){
        return 1;
    }
    return 0;
}
int32_t main(){
    Init
    cin>>n>>m;
    n--;
    for(int i=0;i<m;i++){
        cin>>inp[i].F>>inp[i].S;
        inp[i].F--;
        if(inp[i].F==n){
            cout<<inp[i].S<<endl;
            return 0;
        }
    }
    sort(inp,inp+m);
    int cnt=0;
    int ind;
    for(int i=1;i<101;i++){
        bool is=1;
        for(int j=0;j<m;j++){
            /*
            if(i==3){
                cout<<inp[j].F<<' '<<inp[j].S<<' '<<inp[j].S*(i-1)<<' '<<inp[j].S*(i)<<' '<<ok(inp[j].S*(i-1),inp[j].S*(i),inp[j].F)<<endl;
            }
            */
            if(!ok((inp[j].S-1)*i,(inp[j].S)*(i),inp[j].F)){
                is=0;
            }
        }
        if(is){
            if(!cnt){
                ind = (n/i)+1;
            }
            cnt++;
        }
    }
    if(cnt==1){
        cout<<ind;
    }else{
        cout<<-1;
    }
}


///        +====================+
///        "In The Name Of Allah"
///    +----+------------------+----+
///    |2017| Ali Mollahoseini |1396|
///    | 09 +------------------+ 06 |
///    | 17 |   CF Round 434   | 26 |
///    +----+------------------+----+

#include <bits/stdc++.h>
#define ll long long
#define int long long
#define F first
#define S second
#define pb push_back
#define Init ios::sync_with_stdio(0),cin.tie(0);

const int MX = 2000 + 1000, inf = 0x7FFFFFFF, mod = 1000 * 1000 * 1000 + 7;
using namespace std;
int n , m;
pair<int,int> inp[MX];
bool ok(int l ,int r,int x){
    if(l<=x && x<r){
        return 1;
    }
    return 0;
}
int32_t main(){
    Init
    cin>>n>>m;
    n--;
    if(n==0){
        cout<<1<<endl;
        return 0;
    }
    for(int i=0;i<m;i++){
        cin>>inp[i].F>>inp[i].S;
        inp[i].F--;
        if(inp[i].F==n){
            cout<<inp[i].S<<endl;
            return 0;
        }
    }
    sort(inp,inp+m);
    int cnt=0;
    int ind=-10;
    for(int i=1;i<102;i++){
        bool is=1;
        for(int j=0;j<m;j++){

            if(!ok((inp[j].S-1)*i,(inp[j].S)*(i),inp[j].F)){
                is=0;
            }
        }
        if(is){
            int tmp = ind;
            if(!cnt){
                ind = (n/i)+1;
            }
            if(((n/i)+1) != tmp){
                cnt++;
            }
        }
    }
    if(cnt==1){
        cout<<ind;
    }else if(n>inp[m-1].F){
        cout<<-1<<endl;
    }else{
        int cur =0;
        int floor=1;
        for(int i=0;i<m;i++){
            //cout<<n<<' '<<(cur<=n)<<' '<<(n<inp[i].F)<<' '<<(inp[i].S==floor)<<endl;
            if(cur<=n && n<inp[i].F &&inp[i].S==floor){
                cout<<floor<<endl;
                return 0;
            }else{
                cur = inp[i].F;
                floor = inp[i].S;
            }
        }
        cout<<-1<<endl;
    }
}


///        +====================+
///        "In The Name Of Allah"
///    +----+------------------+----+
///    |2017| Ali Mollahoseini |1396|
///    | 09 +------------------+ 06 |
///    | 17 |   CF Round 434   | 26 |
///    +----+------------------+----+

#include <bits/stdc++.h>
#define ll long long
#define int long long
#define F first
#define S second
#define pb push_back
#define Init ios::sync_with_stdio(0),cin.tie(0);

const int MX = 2000 + 1000, inf = 0x7FFFFFFF, mod = 1000 * 1000 * 1000 + 7;
using namespace std;
int n , m;
pair<int,int> inp[MX];
bool ok(int l ,int r,int x){
    if(l<=x && x<r){
        return 1;
    }
    return 0;
}
int32_t main(){
    Init
    cin>>n>>m;
    n--;
    for(int i=0;i<m;i++){
        cin>>inp[i].F>>inp[i].S;
        inp[i].F--;
        if(inp[i].F==n){
            cout<<inp[i].S<<endl;
            return 0;
        }
    }
    sort(inp,inp+m);
    int cnt=0;
    int ind;
    for(int i=1;i<102;i++){
        bool is=1;
        for(int j=0;j<m;j++){
            /*
            if(i==3){
                cout<<inp[j].F<<' '<<inp[j].S<<' '<<inp[j].S*(i-1)<<' '<<inp[j].S*(i)<<' '<<ok(inp[j].S*(i-1),inp[j].S*(i),inp[j].F)<<endl;
            }
            */
            if(!ok((inp[j].S-1)*i,(inp[j].S)*(i),inp[j].F)){
                is=0;
            }
        }
        if(is){
            if(!cnt){
                ind = (n/i)+1;
            }
            cnt++;
        }
    }
    if(cnt==1){
        cout<<ind;
    }else if(n>inp[m-1].F){
        cout<<-1<<endl;
    }else{
        int cur =0;
        int floor=1;
        for(int i=0;i<m;i++){
            //cout<<n<<' '<<(cur<=n)<<' '<<(n<inp[i].F)<<' '<<(inp[i].S==floor)<<endl;
            if(cur<=n && n<inp[i].F &&inp[i].S==floor){
                cout<<floor<<endl;
                return 0;
            }else{
                cur = inp[i].F;
                floor = inp[i].S;
            }
        }
        cout<<-1<<endl;
    }
}


///        +====================+
///        "In The Name Of Allah"
///    +----+------------------+----+
///    |2017| Ali Mollahoseini |1396|
///    | 09 +------------------+ 06 |
///    | 17 |   CF Round 434   | 26 |
///    +----+------------------+----+

#include <bits/stdc++.h>
#define ll long long
#define int long long
#define F first
#define S second
#define pb push_back
#define Init ios::sync_with_stdio(0),cin.tie(0);

const int MX = 2000 + 1000, inf = 0x7FFFFFFF, mod = 1000 * 1000 * 1000 + 7;
using namespace std;
int n , m;
pair<int,int> inp[MX];
bool ok(int l ,int r,int x){
    if(l<=x && x<r){
        return 1;
    }
    return 0;
}
int32_t main(){
    Init
    cin>>n>>m;
    n--;
    if(n==0){
        cout<<1<<endl;
        return 0;
    }
    for(int i=0;i<m;i++){
        cin>>inp[i].F>>inp[i].S;
        inp[i].F--;
        if(inp[i].F==n){
            cout<<inp[i].S<<endl;
            return 0;
        }
    }
    sort(inp,inp+m);
    int cnt=0;
    int ind;
    for(int i=1;i<102;i++){
        bool is=1;
        for(int j=0;j<m;j++){
            /*
            if(i==3){
                cout<<inp[j].F<<' '<<inp[j].S<<' '<<inp[j].S*(i-1)<<' '<<inp[j].S*(i)<<' '<<ok(inp[j].S*(i-1),inp[j].S*(i),inp[j].F)<<endl;
            }
            */
            if(!ok((inp[j].S-1)*i,(inp[j].S)*(i),inp[j].F)){
                is=0;
            }
        }
        if(is){
            if(!cnt){
                ind = (n/i)+1;
            }
            cnt++;
        }
    }
    if(cnt==1){
        cout<<ind;
    }else if(n>inp[m-1].F){
        cout<<-1<<endl;
    }else{
        int cur =0;
        int floor=1;
        for(int i=0;i<m;i++){
            //cout<<n<<' '<<(cur<=n)<<' '<<(n<inp[i].F)<<' '<<(inp[i].S==floor)<<endl;
            if(cur<=n && n<inp[i].F &&inp[i].S==floor){
                cout<<floor<<endl;
                return 0;
            }else{
                cur = inp[i].F;
                floor = inp[i].S;
            }
        }
        cout<<-1<<endl;
    }
}


#include <bits/stdc++.h>

#define loop(i,s,e) for(int i = s;i<=e;i++) //including end point

#define pb(a) push_back(a)

#define sqr(x) ((x)*(x))

#define CIN ios_base::sync_with_stdio(0); cin.tie(0);

#define ll long long

#define ull unsigned long long

#define SZ(a) int(a.size())

#define read() freopen("input.txt", "r", stdin)

#define write() freopen("output.txt", "w", stdout)

#define ms(a,b) memset(a, b, sizeof(a))

#define all(v) v.begin(), v.end()

#define PI acos(-1.0)

#define pf printf

#define sfi(a) scanf("%d",&a);

#define sfii(a,b) scanf("%d %d",&a,&b);

#define sfl(a) scanf("%lld",&a);

#define sfll(a,b) scanf("%lld %lld",&a,&b);

#define sful(a) scanf("%llu",&a);

#define sfulul(a,b) scanf("%llu %llu",&a,&b);

#define sful2(a,b) scanf("%llu %llu",&a,&b); // A little different

#define sfc(a) scanf("%c",&a);

#define sfs(a) scanf("%s",a);

#define getl(s) getline(cin,s);

#define mp make_pair

#define paii pair<int, int>

#define padd pair<dd, dd>

#define pall pair<ll, ll>

#define vi vector<int>

#define vll vector<ll>

#define mii map<int,int>

#define mlli map<ll,int>

#define mib map<int,bool>

#define fs first

#define sc second

#define CASE(t) printf("Case %d: ",++t) // t initialized 0

#define cCASE(t) cout<<"Case "<<++t<<": ";

#define D(v,status) cout<<status<<" "<<v<<endl;

#define INF 1000000000   //10e9

#define EPS 1e-9

#define flc fflush(stdout); //For interactive programs , flush while using pf (that's why __c )

#define CONTEST 1
using namespace std;

//Bit Manipulation
bool Check_ON(int mask,int pos) //Check if pos th bit (from right) of mask is ON
{
    if( (mask & (1<<pos) ) == 0  )return false;
    return true;
}
int SET(int mask,int pos) //Save the returned mask into some var //Turn on pos th bit in mask
{
    return (mask | (1<<pos));
}
int RESET(int mask,int pos)  //Save the returned mask into some var //Turn off pos th bit in mask
{
    return (mask & ~(1<<pos));
}
int FLIP(int mask,int pos) //Save the returned mask into some var //Toggle/Flip pos th bit in mask
{
    return (mask ^ (1<<pos));
}
int LSB(int mask) // The actual LSB mask
{
    return (mask & (-mask));
}
int LSB_pos(int mask) // 0 based position
{
    int mask_2 = (mask & (-mask));
    for(int pos = 0; pos<=15; pos++)
    {
        if(Check_ON(mask_2,pos))
            return pos;
    }
    return -1;//
}
int ON_Bits(int mask)
{
    return __builtin_popcount(mask);
}
inline int clz(int N)   // O(1) way to calculate log2(X) (int s only)
{
    return N ? 32 - __builtin_clz(N) : -INF;
}

int flta[105];
int flra[105];
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        for(int i=1; i<=m; i++)
        {
            int flr,ft;
            cin>>flr>>ft;
            //flt[flr] = ft;

            flta[i] = ft;
            flra[i] = flr;

        }

        int flg = 0;

        int lastans = 0;

        for(int j=1; j<=m; j++)
        {
            for(int k=1; k<=m; k++)
            {
                if(flra[k]==flra[j]+1
                        && (flta[k]==flta[j]+1))
                {
                    flg = 1;
                    lastans = flra[j]/flta[j];
                }

            }
        }

        /*
        int cnt = 0;
        int lastan = 1;
        for(int nf=1; nf<=100; nf++)
        {
            int flg = 1;
            for(int cf=1; cf<=m; cf++)
            {
                int cff = flra[cf];
                int cnv = cff/nf;
                if(cff%nf!=0)
                cnv++;

                if(cnv!=flta[cf])
                {
                    flg = 0;
                }
            }
            if(flg)
            {
                cnt++;
                lastan = nf;
            }

            if(cnt>1)
                break;

        }

        */

        if(flg==0)
        {
            cout<<-1<<endl;
        }
        else
        {
            int ansa = n/lastans;
            if(n%lastans!=0)
                ansa++;
            cout<<ansa<<endl;
        }

    }
    return 0;
}


#include <bits/stdc++.h>

#define loop(i,s,e) for(int i = s;i<=e;i++) //including end point

#define pb(a) push_back(a)

#define sqr(x) ((x)*(x))

#define CIN ios_base::sync_with_stdio(0); cin.tie(0);

#define ll long long

#define ull unsigned long long

#define SZ(a) int(a.size())

#define read() freopen("input.txt", "r", stdin)

#define write() freopen("output.txt", "w", stdout)

#define ms(a,b) memset(a, b, sizeof(a))

#define all(v) v.begin(), v.end()

#define PI acos(-1.0)

#define pf printf

#define sfi(a) scanf("%d",&a);

#define sfii(a,b) scanf("%d %d",&a,&b);

#define sfl(a) scanf("%lld",&a);

#define sfll(a,b) scanf("%lld %lld",&a,&b);

#define sful(a) scanf("%llu",&a);

#define sfulul(a,b) scanf("%llu %llu",&a,&b);

#define sful2(a,b) scanf("%llu %llu",&a,&b); // A little different

#define sfc(a) scanf("%c",&a);

#define sfs(a) scanf("%s",a);

#define getl(s) getline(cin,s);

#define mp make_pair

#define paii pair<int, int>

#define padd pair<dd, dd>

#define pall pair<ll, ll>

#define vi vector<int>

#define vll vector<ll>

#define mii map<int,int>

#define mlli map<ll,int>

#define mib map<int,bool>

#define fs first

#define sc second

#define CASE(t) printf("Case %d: ",++t) // t initialized 0

#define cCASE(t) cout<<"Case "<<++t<<": ";

#define D(v,status) cout<<status<<" "<<v<<endl;

#define INF 1000000000   //10e9

#define EPS 1e-9

#define flc fflush(stdout); //For interactive programs , flush while using pf (that's why __c )

#define CONTEST 1
using namespace std;

//Bit Manipulation
bool Check_ON(int mask,int pos) //Check if pos th bit (from right) of mask is ON
{
    if( (mask & (1<<pos) ) == 0  )return false;
    return true;
}
int SET(int mask,int pos) //Save the returned mask into some var //Turn on pos th bit in mask
{
    return (mask | (1<<pos));
}
int RESET(int mask,int pos)  //Save the returned mask into some var //Turn off pos th bit in mask
{
    return (mask & ~(1<<pos));
}
int FLIP(int mask,int pos) //Save the returned mask into some var //Toggle/Flip pos th bit in mask
{
    return (mask ^ (1<<pos));
}
int LSB(int mask) // The actual LSB mask
{
    return (mask & (-mask));
}
int LSB_pos(int mask) // 0 based position
{
    int mask_2 = (mask & (-mask));
    for(int pos = 0; pos<=15; pos++)
    {
        if(Check_ON(mask_2,pos))
            return pos;
    }
    return -1;//
}
int ON_Bits(int mask)
{
    return __builtin_popcount(mask);
}
inline int clz(int N)   // O(1) way to calculate log2(X) (int s only)
{
    return N ? 32 - __builtin_clz(N) : -INF;
}
set<int>una;
int flta[105];
int flra[105];
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        for(int i=1;i<=m;i++)
        {
            cin>>flra[i]>>flta[i];

            if(flra[i]==n)
            {
                cout<<flta[i]<<endl;
                return 0;
            }
        }

        int ans = 1;

        for(int nf=1;nf<=200;nf++)
        {
            for(int aft=1;aft<=200;aft++)
            {
                int flg = 1;
                for(int j=1;j<=m;j++)
                {
                    if(flra[j]/nf + (flra[j]%nf!=0) != flta[j])
                    {
                        flg = 0;
                    }
                }

                if(n/nf + (n%nf!=0)!=aft)
                {
                    flg = 0;
                }

                if(flg)
                una.insert(aft);

            }
        }

        if(una.size()==1)
            cout<<*(una.begin())<<endl;
        else
            cout<<-1<<endl;

        una.clear();

    }

    return 0;
}


#include <bits/stdc++.h>

#define loop(i,s,e) for(int i = s;i<=e;i++) //including end point

#define pb(a) push_back(a)

#define sqr(x) ((x)*(x))

#define CIN ios_base::sync_with_stdio(0); cin.tie(0);

#define ll long long

#define ull unsigned long long

#define SZ(a) int(a.size())

#define read() freopen("input.txt", "r", stdin)

#define write() freopen("output.txt", "w", stdout)

#define ms(a,b) memset(a, b, sizeof(a))

#define all(v) v.begin(), v.end()

#define PI acos(-1.0)

#define pf printf

#define sfi(a) scanf("%d",&a);

#define sfii(a,b) scanf("%d %d",&a,&b);

#define sfl(a) scanf("%lld",&a);

#define sfll(a,b) scanf("%lld %lld",&a,&b);

#define sful(a) scanf("%llu",&a);

#define sfulul(a,b) scanf("%llu %llu",&a,&b);

#define sful2(a,b) scanf("%llu %llu",&a,&b); // A little different

#define sfc(a) scanf("%c",&a);

#define sfs(a) scanf("%s",a);

#define getl(s) getline(cin,s);

#define mp make_pair

#define paii pair<int, int>

#define padd pair<dd, dd>

#define pall pair<ll, ll>

#define vi vector<int>

#define vll vector<ll>

#define mii map<int,int>

#define mlli map<ll,int>

#define mib map<int,bool>

#define fs first

#define sc second

#define CASE(t) printf("Case %d: ",++t) // t initialized 0

#define cCASE(t) cout<<"Case "<<++t<<": ";

#define D(v,status) cout<<status<<" "<<v<<endl;

#define INF 1000000000   //10e9

#define EPS 1e-9

#define flc fflush(stdout); //For interactive programs , flush while using pf (that's why __c )

#define CONTEST 1
using namespace std;

//Bit Manipulation
bool Check_ON(int mask,int pos) //Check if pos th bit (from right) of mask is ON
{
    if( (mask & (1<<pos) ) == 0  )return false;
    return true;
}
int SET(int mask,int pos) //Save the returned mask into some var //Turn on pos th bit in mask
{
    return (mask | (1<<pos));
}
int RESET(int mask,int pos)  //Save the returned mask into some var //Turn off pos th bit in mask
{
    return (mask & ~(1<<pos));
}
int FLIP(int mask,int pos) //Save the returned mask into some var //Toggle/Flip pos th bit in mask
{
    return (mask ^ (1<<pos));
}
int LSB(int mask) // The actual LSB mask
{
    return (mask & (-mask));
}
int LSB_pos(int mask) // 0 based position
{
    int mask_2 = (mask & (-mask));
    for(int pos = 0; pos<=15; pos++)
    {
        if(Check_ON(mask_2,pos))
            return pos;
    }
    return -1;//
}
int ON_Bits(int mask)
{
    return __builtin_popcount(mask);
}
inline int clz(int N)   // O(1) way to calculate log2(X) (int s only)
{
    return N ? 32 - __builtin_clz(N) : -INF;
}
set<int>una;
int flta[105];
int flra[105];
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        int special = 0;
        for(int i=1; i<=m; i++)
        {
            int flr,ft;
            cin>>flr>>ft;
            //flt[flr] = ft;

            if(flr==n)
                special = ft;

            flta[i] = ft;
            flra[i] = flr;

            if(flta[i]%2==0 &&
               flra[i]==n-1
               && flra[i]%2)
            {
                special = flta[i];
            }

        }

        int flg = 0;

        int lastans = 0;

        for(int j=1; j<=m; j++)
        {
            for(int k=1; k<=m; k++)
            {
                if(flra[j]<=n && flra[k]>=n
                        && flta[j]==flta[k])
                {
                    special = flta[j];
                }

            }
        }

        int cnt = 0;
        int lastan = 1;
        for(int nf=1; nf<=100; nf++)
        {
            int flg = 1;
            for(int cf=1; cf<=m; cf++)
            {
                int cff = flra[cf];
                int cnv = cff/nf;
                if(cff%nf!=0)
                    cnv++;

                if(cnv!=flta[cf])
                {
                    flg = 0;
                }
            }
            if(flg)
            {
                cnt++;
                lastan = nf;
                una.insert(nf);
            }

        }

        if(special!=0)
        {
            cout<<special<<endl;
        }

        else if(una.size()>1)
        {
            cout<<-1<<endl;
        }
        else
        {
            //lastan = *una.begin();
            int ansa = n/lastan;
            if(n%lastan!=0)
                ansa++;
            cout<<ansa<<endl;
        }

    }
    return 0;
}


#include <bits/stdc++.h>

#define loop(i,s,e) for(int i = s;i<=e;i++) //including end point

#define pb(a) push_back(a)

#define sqr(x) ((x)*(x))

#define CIN ios_base::sync_with_stdio(0); cin.tie(0);

#define ll long long

#define ull unsigned long long

#define SZ(a) int(a.size())

#define read() freopen("input.txt", "r", stdin)

#define write() freopen("output.txt", "w", stdout)

#define ms(a,b) memset(a, b, sizeof(a))

#define all(v) v.begin(), v.end()

#define PI acos(-1.0)

#define pf printf

#define sfi(a) scanf("%d",&a);

#define sfii(a,b) scanf("%d %d",&a,&b);

#define sfl(a) scanf("%lld",&a);

#define sfll(a,b) scanf("%lld %lld",&a,&b);

#define sful(a) scanf("%llu",&a);

#define sfulul(a,b) scanf("%llu %llu",&a,&b);

#define sful2(a,b) scanf("%llu %llu",&a,&b); // A little different

#define sfc(a) scanf("%c",&a);

#define sfs(a) scanf("%s",a);

#define getl(s) getline(cin,s);

#define mp make_pair

#define paii pair<int, int>

#define padd pair<dd, dd>

#define pall pair<ll, ll>

#define vi vector<int>

#define vll vector<ll>

#define mii map<int,int>

#define mlli map<ll,int>

#define mib map<int,bool>

#define fs first

#define sc second

#define CASE(t) printf("Case %d: ",++t) // t initialized 0

#define cCASE(t) cout<<"Case "<<++t<<": ";

#define D(v,status) cout<<status<<" "<<v<<endl;

#define INF 1000000000   //10e9

#define EPS 1e-9

#define flc fflush(stdout); //For interactive programs , flush while using pf (that's why __c )

#define CONTEST 1
using namespace std;

//Bit Manipulation
bool Check_ON(int mask,int pos) //Check if pos th bit (from right) of mask is ON
{
    if( (mask & (1<<pos) ) == 0  )return false;
    return true;
}
int SET(int mask,int pos) //Save the returned mask into some var //Turn on pos th bit in mask
{
    return (mask | (1<<pos));
}
int RESET(int mask,int pos)  //Save the returned mask into some var //Turn off pos th bit in mask
{
    return (mask & ~(1<<pos));
}
int FLIP(int mask,int pos) //Save the returned mask into some var //Toggle/Flip pos th bit in mask
{
    return (mask ^ (1<<pos));
}
int LSB(int mask) // The actual LSB mask
{
    return (mask & (-mask));
}
int LSB_pos(int mask) // 0 based position
{
    int mask_2 = (mask & (-mask));
    for(int pos = 0; pos<=15; pos++)
    {
        if(Check_ON(mask_2,pos))
            return pos;
    }
    return -1;//
}
int ON_Bits(int mask)
{
    return __builtin_popcount(mask);
}
inline int clz(int N)   // O(1) way to calculate log2(X) (int s only)
{
    return N ? 32 - __builtin_clz(N) : -INF;
}

int flta[105];
int flra[105];
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        int special = 0;
        for(int i=1; i<=m; i++)
        {
            int flr,ft;
            cin>>flr>>ft;
            //flt[flr] = ft;

            if(flr==n)
                special = ft;

            flta[i] = ft;
            flra[i] = flr;

        }

        int flg = 0;

        int lastans = 0;

        for(int j=1; j<=m; j++)
        {
            for(int k=1; k<=m; k++)
            {
                if(flra[j]<=n && flra[k]>=n
                        && flta[j]==flta[k])
                {
                    special = flta[j];
                }

            }
        }

        int cnt = 0;
        int lastan = 1;
        for(int nf=1; nf<=100; nf++)
        {
            int flg = 1;
            for(int cf=1; cf<=m; cf++)
            {
                int cff = flra[cf];
                int cnv = cff/nf;
                if(cff%nf!=0)
                    cnv++;

                if(cnv!=flta[cf])
                {
                    flg = 0;
                }
            }
            if(flg)
            {
                cnt++;
                lastan = nf;
            }

            if(cnt>1)
                break;

        }

        if(special!=0)
        {
            cout<<special<<endl;
        }

        else if(cnt==0 || cnt>1)
        {
            cout<<-1<<endl;
        }
        else
        {
            int ansa = n/lastan;
            if(n%lastan!=0)
                ansa++;
            cout<<ansa<<endl;
        }

    }
    return 0;
}


#include <bits/stdc++.h>

#define loop(i,s,e) for(int i = s;i<=e;i++) //including end point

#define pb(a) push_back(a)

#define sqr(x) ((x)*(x))

#define CIN ios_base::sync_with_stdio(0); cin.tie(0);

#define ll long long

#define ull unsigned long long

#define SZ(a) int(a.size())

#define read() freopen("input.txt", "r", stdin)

#define write() freopen("output.txt", "w", stdout)

#define ms(a,b) memset(a, b, sizeof(a))

#define all(v) v.begin(), v.end()

#define PI acos(-1.0)

#define pf printf

#define sfi(a) scanf("%d",&a);

#define sfii(a,b) scanf("%d %d",&a,&b);

#define sfl(a) scanf("%lld",&a);

#define sfll(a,b) scanf("%lld %lld",&a,&b);

#define sful(a) scanf("%llu",&a);

#define sfulul(a,b) scanf("%llu %llu",&a,&b);

#define sful2(a,b) scanf("%llu %llu",&a,&b); // A little different

#define sfc(a) scanf("%c",&a);

#define sfs(a) scanf("%s",a);

#define getl(s) getline(cin,s);

#define mp make_pair

#define paii pair<int, int>

#define padd pair<dd, dd>

#define pall pair<ll, ll>

#define vi vector<int>

#define vll vector<ll>

#define mii map<int,int>

#define mlli map<ll,int>

#define mib map<int,bool>

#define fs first

#define sc second

#define CASE(t) printf("Case %d: ",++t) // t initialized 0

#define cCASE(t) cout<<"Case "<<++t<<": ";

#define D(v,status) cout<<status<<" "<<v<<endl;

#define INF 1000000000   //10e9

#define EPS 1e-9

#define flc fflush(stdout); //For interactive programs , flush while using pf (that's why __c )

#define CONTEST 1
using namespace std;

//Bit Manipulation
bool Check_ON(int mask,int pos) //Check if pos th bit (from right) of mask is ON
{
    if( (mask & (1<<pos) ) == 0  )return false;
    return true;
}
int SET(int mask,int pos) //Save the returned mask into some var //Turn on pos th bit in mask
{
    return (mask | (1<<pos));
}
int RESET(int mask,int pos)  //Save the returned mask into some var //Turn off pos th bit in mask
{
    return (mask & ~(1<<pos));
}
int FLIP(int mask,int pos) //Save the returned mask into some var //Toggle/Flip pos th bit in mask
{
    return (mask ^ (1<<pos));
}
int LSB(int mask) // The actual LSB mask
{
    return (mask & (-mask));
}
int LSB_pos(int mask) // 0 based position
{
    int mask_2 = (mask & (-mask));
    for(int pos = 0; pos<=15; pos++)
    {
        if(Check_ON(mask_2,pos))
            return pos;
    }
    return -1;//
}
int ON_Bits(int mask)
{
    return __builtin_popcount(mask);
}
inline int clz(int N)   // O(1) way to calculate log2(X) (int s only)
{
    return N ? 32 - __builtin_clz(N) : -INF;
}

int flta[105];
int flra[105];
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        int special = 0;
        for(int i=1; i<=m; i++)
        {
            int flr,ft;
            cin>>flr>>ft;
            //flt[flr] = ft;

            if(flr==n)
                special = ft;

            flta[i] = ft;
            flra[i] = flr;

        }

        int flg = 0;

        int lastans = 0;

        for(int j=1; j<=m; j++)
        {
            for(int k=1; k<=m; k++)
            {
                if(flra[k]==flra[j]+1
                        && (flta[k]==flta[j]+1))
                {
                    flg = 1;
                    lastans = flra[j]/flta[j];
                }

            }
        }

        /*
        int cnt = 0;
        int lastan = 1;
        for(int nf=1; nf<=100; nf++)
        {
            int flg = 1;
            for(int cf=1; cf<=m; cf++)
            {
                int cff = flra[cf];
                int cnv = cff/nf;
                if(cff%nf!=0)
                cnv++;

                if(cnv!=flta[cf])
                {
                    flg = 0;
                }
            }
            if(flg)
            {
                cnt++;
                lastan = nf;
            }

            if(cnt>1)
                break;

        }

        */

        if(special!=0)
        {
            cout<<special<<endl;
        }

        else if(flg==0)
        {
            cout<<-1<<endl;
        }
        else
        {
            int ansa = n/lastans;
            if(n%lastans!=0)
                ansa++;
            cout<<ansa<<endl;
        }

    }
    return 0;
}


#include <bits/stdc++.h>

#define loop(i,s,e) for(int i = s;i<=e;i++) //including end point

#define pb(a) push_back(a)

#define sqr(x) ((x)*(x))

#define CIN ios_base::sync_with_stdio(0); cin.tie(0);

#define ll long long

#define ull unsigned long long

#define SZ(a) int(a.size())

#define read() freopen("input.txt", "r", stdin)

#define write() freopen("output.txt", "w", stdout)

#define ms(a,b) memset(a, b, sizeof(a))

#define all(v) v.begin(), v.end()

#define PI acos(-1.0)

#define pf printf

#define sfi(a) scanf("%d",&a);

#define sfii(a,b) scanf("%d %d",&a,&b);

#define sfl(a) scanf("%lld",&a);

#define sfll(a,b) scanf("%lld %lld",&a,&b);

#define sful(a) scanf("%llu",&a);

#define sfulul(a,b) scanf("%llu %llu",&a,&b);

#define sful2(a,b) scanf("%llu %llu",&a,&b); // A little different

#define sfc(a) scanf("%c",&a);

#define sfs(a) scanf("%s",a);

#define getl(s) getline(cin,s);

#define mp make_pair

#define paii pair<int, int>

#define padd pair<dd, dd>

#define pall pair<ll, ll>

#define vi vector<int>

#define vll vector<ll>

#define mii map<int,int>

#define mlli map<ll,int>

#define mib map<int,bool>

#define fs first

#define sc second

#define CASE(t) printf("Case %d: ",++t) // t initialized 0

#define cCASE(t) cout<<"Case "<<++t<<": ";

#define D(v,status) cout<<status<<" "<<v<<endl;

#define INF 1000000000   //10e9

#define EPS 1e-9

#define flc fflush(stdout); //For interactive programs , flush while using pf (that's why __c )

#define CONTEST 1
using namespace std;

//Bit Manipulation
bool Check_ON(int mask,int pos) //Check if pos th bit (from right) of mask is ON
{
    if( (mask & (1<<pos) ) == 0  )return false;
    return true;
}
int SET(int mask,int pos) //Save the returned mask into some var //Turn on pos th bit in mask
{
    return (mask | (1<<pos));
}
int RESET(int mask,int pos)  //Save the returned mask into some var //Turn off pos th bit in mask
{
    return (mask & ~(1<<pos));
}
int FLIP(int mask,int pos) //Save the returned mask into some var //Toggle/Flip pos th bit in mask
{
    return (mask ^ (1<<pos));
}
int LSB(int mask) // The actual LSB mask
{
    return (mask & (-mask));
}
int LSB_pos(int mask) // 0 based position
{
    int mask_2 = (mask & (-mask));
    for(int pos = 0; pos<=15; pos++)
    {
        if(Check_ON(mask_2,pos))
            return pos;
    }
    return -1;//
}
int ON_Bits(int mask)
{
    return __builtin_popcount(mask);
}
inline int clz(int N)   // O(1) way to calculate log2(X) (int s only)
{
    return N ? 32 - __builtin_clz(N) : -INF;
}

int flta[105];
int flra[105];
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        int special = 0;
        for(int i=1; i<=m; i++)
        {
            int flr,ft;
            cin>>flr>>ft;
            //flt[flr] = ft;

            if(flr==n)
                special = ft;

            flta[i] = ft;
            flra[i] = flr;

            if(flra[i]==n-1
               && flra[i]%2)
            {
                special = flta[i];
            }

        }

        int flg = 0;

        int lastans = 0;

        for(int j=1; j<=m; j++)
        {
            for(int k=1; k<=m; k++)
            {
                if(flra[j]<=n && flra[k]>=n
                        && flta[j]==flta[k])
                {
                    special = flta[j];
                }

            }
        }

        int cnt = 0;
        int lastan = 1;
        for(int nf=1; nf<=100; nf++)
        {
            int flg = 1;
            for(int cf=1; cf<=m; cf++)
            {
                int cff = flra[cf];
                int cnv = cff/nf;
                if(cff%nf!=0)
                    cnv++;

                if(cnv!=flta[cf])
                {
                    flg = 0;
                }
            }
            if(flg)
            {
                cnt++;
                lastan = nf;
            }

            if(cnt>1)
                break;

        }

        if(special!=0)
        {
            cout<<special<<endl;
        }

        else if(cnt==0 || cnt>1)
        {
            cout<<-1<<endl;
        }
        else
        {
            int ansa = n/lastan;
            if(n%lastan!=0)
                ansa++;
            cout<<ansa<<endl;
        }

    }
    return 0;
}


#include <bits/stdc++.h>

#define loop(i,s,e) for(int i = s;i<=e;i++) //including end point

#define pb(a) push_back(a)

#define sqr(x) ((x)*(x))

#define CIN ios_base::sync_with_stdio(0); cin.tie(0);

#define ll long long

#define ull unsigned long long

#define SZ(a) int(a.size())

#define read() freopen("input.txt", "r", stdin)

#define write() freopen("output.txt", "w", stdout)

#define ms(a,b) memset(a, b, sizeof(a))

#define all(v) v.begin(), v.end()

#define PI acos(-1.0)

#define pf printf

#define sfi(a) scanf("%d",&a);

#define sfii(a,b) scanf("%d %d",&a,&b);

#define sfl(a) scanf("%lld",&a);

#define sfll(a,b) scanf("%lld %lld",&a,&b);

#define sful(a) scanf("%llu",&a);

#define sfulul(a,b) scanf("%llu %llu",&a,&b);

#define sful2(a,b) scanf("%llu %llu",&a,&b); // A little different

#define sfc(a) scanf("%c",&a);

#define sfs(a) scanf("%s",a);

#define getl(s) getline(cin,s);

#define mp make_pair

#define paii pair<int, int>

#define padd pair<dd, dd>

#define pall pair<ll, ll>

#define vi vector<int>

#define vll vector<ll>

#define mii map<int,int>

#define mlli map<ll,int>

#define mib map<int,bool>

#define fs first

#define sc second

#define CASE(t) printf("Case %d: ",++t) // t initialized 0

#define cCASE(t) cout<<"Case "<<++t<<": ";

#define D(v,status) cout<<status<<" "<<v<<endl;

#define INF 1000000000   //10e9

#define EPS 1e-9

#define flc fflush(stdout); //For interactive programs , flush while using pf (that's why __c )

#define CONTEST 1
using namespace std;

//Bit Manipulation
bool Check_ON(int mask,int pos) //Check if pos th bit (from right) of mask is ON
{
    if( (mask & (1<<pos) ) == 0  )return false;
    return true;
}
int SET(int mask,int pos) //Save the returned mask into some var //Turn on pos th bit in mask
{
    return (mask | (1<<pos));
}
int RESET(int mask,int pos)  //Save the returned mask into some var //Turn off pos th bit in mask
{
    return (mask & ~(1<<pos));
}
int FLIP(int mask,int pos) //Save the returned mask into some var //Toggle/Flip pos th bit in mask
{
    return (mask ^ (1<<pos));
}
int LSB(int mask) // The actual LSB mask
{
    return (mask & (-mask));
}
int LSB_pos(int mask) // 0 based position
{
    int mask_2 = (mask & (-mask));
    for(int pos = 0; pos<=15; pos++)
    {
        if(Check_ON(mask_2,pos))
            return pos;
    }
    return -1;//
}
int ON_Bits(int mask)
{
    return __builtin_popcount(mask);
}
inline int clz(int N)   // O(1) way to calculate log2(X) (int s only)
{
    return N ? 32 - __builtin_clz(N) : -INF;
}

int flta[105];
int flra[105];
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        for(int i=1; i<=m; i++)
        {
            int flr,ft;
            cin>>flr>>ft;
            //flt[flr] = ft;

            flta[i] = ft;
            flra[i] = flr;

        }
        int cnt = 0;
        int lastan = 1;
        for(int nf=1; nf<=100; nf++)
        {
            int flg = 1;
            for(int cf=1; cf<=m; cf++)
            {
                int cff = flra[cf];
                int cnv = cff/nf;
                if(cff%nf!=0)
                cnv++;

                if(cnv!=flta[cf])
                {
                    flg = 0;
                }
            }
            if(flg)
            {
                cnt++;
                lastan = nf;
            }

            if(cnt>1)
                break;

        }

        if(cnt>1 || cnt==0)
        {
            cout<<-1<<endl;
        }
        else
        {
            int ansa = n/lastan;
            if(n%lastan!=0)
                ansa++;
            cout<<ansa<<endl;
        }

    }
    return 0;
}