#include
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main () {
ll ans=INT_MIN;
ll n,m;
ll dp[n+1][n+1];
ll x,y;
cin>>n>>m;
for(ll i=0;i<m;i++){
cin>>x>>y;
dp[x-1][y-1]++;
}
for(int i=1;i<n;i++){
for(int j=1;j<n;j++){
dp[i][j]+=dp[i-1][j];
}
}
for(int i=1;i<n;i++){
for(int j=1;j<n;j++){
dp[i][j]+=dp[i][j-1];
}
}
for(int i=1;i<n;i++){
for(int j=1;j<n;j++){
ans=max(ans,min(dp[i][j],min(dp[n-1][j]-dp[i][j],min(dp[i][n-1]-dp[i][j],dp[n-1][n-1]-dp[n-1][j]-dp[i][n-1]+dp[i][j]))));
}
}
cout<<ans<<endl;
return 0;
}
Getting run error in all the test cases.