//差分
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e6+10;
int A[N];
int B[N];
int main()
{
int n;
int m;
cin >> n >> m;
while (m -- )
{
int a,b;
cin >> a>>b;
A[a]++;
A[b+1]--;
}
for (int i = 1; i <= n; i ++ )
B[i]=B[i-1]+A[i];
sort(B+1,B+n+1);
cout<<B[n/2+1];
}
//枚举
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int a[101];
int b[101];
int cnt[6];
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i ++ )
cnt[i]=0;
for (int i = 0; i < n; i ++ )
cin >>a[i] >> b[i];
for (int i = 0; i < n; i ++ )
{
if(a[i]==1&&b[i]==2||a[i]==2&&b[i]==3||a[i]==3&&b[i]==1)
cnt[0]++;
if(a[i]==1&&b[i]==3||a[i]==3&&b[i]==2||a[i]==2&&b[i]==1)
cnt[1]++;
if(a[i]==2&&b[i]==1||a[i]==1&&b[i]==3||a[i]==3&&b[i]==2)
cnt[2]++;
if(a[i]==2&&b[i]==3||a[i]==3&&b[i]==1||a[i]==1&&b[i]==2)
cnt[3]++;
if(a[i]==3&&b[i]==1||a[i]==1&&b[i]==2||a[i]==2&&b[i]==3)
cnt[4]++;
if(a[i]==3&&b[i]==2||a[i]==2&&b[i]==1||a[i]==1&&b[i]==3)
cnt[5]++;
}
/*
123
132
213
231
312
321
*/
sort(cnt,cnt+6);
cout<<cnt[5];
}