#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using i128=__int128_t;
using u128=__uint128_t;
using ld=long double;
void solve()
{
int n,m,x,y;
cin >> n >> m;
vector<int>v;//将所有可以使用的卷的优惠金额放进去
while(m--)
{
cin >> x >> y;
if(n>=x) v.push_back(y);
}
sort(v.begin(),v.end(),greater<int>());//降序排序 选出优惠力度最大的卷
if(v.empty()) cout << n;//别忘了 一张卷都用不了 要输出n本身
else cout << n-v[0];
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t=1;
//cin >> t;
while(t--)
{
solve();
}
return 0;
}