include[HTML_REMOVED]
include[HTML_REMOVED]
include[HTML_REMOVED]
using namespace std;
const int N=1010;
int n,c;
typedef pair[HTML_REMOVED]PII;
vector[HTML_REMOVED]numbers;
PII points[N];
int sum[N][N];
int get(int x){
int l=0,r=numbers.size()-1;
while(l[HTML_REMOVED]>1;
if(numbers[mid]>=x)r=mid;
else l=mid+1;
}
return r;
}
bool check(int len){
for(int x1=0,x2=1;x2[HTML_REMOVED]len)x1;
for(int y1=0,y2=1;y2[HTML_REMOVED]len)y1;
if(sum[x2][y2]-sum[x1][y2]-sum[x2][y1]+sum[x1][y1]>=c)return true;
}
}
return false;
}
int main(){
cin>>c>>n;
numbers.push_back(0);
for(int i=0;i[HTML_REMOVED]>x>>y;
points[i]={x,y};
numbers.push_back(x);
numbers.push_back(y);
}
sort(numbers.begin(),numbers.end());
numbers.erase(unique(numbers.begin(),numbers.end()),numbers.end());
for(int i=0;i<n;i++){
int x=get(points[i].first),y=get(points[i].second);
sum[x][y]++;
}
for(int i=1;i<numbers.size();i++)
{for(int j=1;j<numbers.size();j++)
sum[i][j]+=sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1];}
int l=1,r=10000;
while(l<r){
int mid=l+r>>1;
if(check(mid))r=mid;
else l=mid+1;
}
cout<<r<<endl;
}