#include <bits/stdc++.h>

using namespace std;

//begin of def

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define endl '\n'

using lli = long long int;
using ulli = unsigned long long int;
using Ld = long double;
using pii = pair<int, int>;
using pll = pair<lli, lli>;
using pld = pair<Ld, Ld>;
#define X first
#define Y second

#define rep(I, S, E) for(int I = (S); I < (E); I++)
#define repq(I, S, E) for(int I = (S); I <= (E); I++)

#define pb push_back
#define epb emplace_back

#define ALL(X) X.begin(), X.end()

//end of def

int main(){
    fastio;
    lli n;
    int m;
    cin >> n >> m;
    vector<pii> v(m);
    rep(i, 0, m)
        cin >> v[i].X >> v[i].Y;
    sort(ALL(v));
    set<lli> st;
    st.insert(n);
    lli nw = -2, er = -2;
    rep(i, 0, m){
        if(i && v[i].X != v[i - 1].X)
            nw = er = -2;
        int t = er;
        if(st.count(v[i].Y))
            er = v[i].Y;
        st.erase(v[i].Y);
        if((st.count(v[i].Y - 1) && nw != v[i].Y - 1) || st.count(v[i].Y + 1) || t == v[i].Y - 1){
            if(st.count(v[i].Y) == 0)
                nw = v[i].Y;
            st.insert(v[i].Y);
        }
    }
    cout << st.size();
    return 0;
}

// Problem: C - Max GCD 2
// Contest: AtCoder - Japanese Student Championship 2021
// URL: https://atcoder.jp/contests/jsc2021/tasks/jsc2021_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define pb push_back
#define mp make_pair
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9+7;
const int MAX_N = 2e6+10;

int a, b;

void solve()
{
	int ans = 1;
	for(int i=1;i<=b;++i){
		int mi = (a + i-1)/ i;
		int mx = b / i;
		if(mx > mi) ans = i;
	}
	cout << ans << '\n';
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cin >> a >> b;
	solve();
	return 0;
}