#include<bits/stdc++.h>
#define ll long long
using namespace std;
///map< ll , ll > dp[101101];
ll a[101101], b[101101];
int main(){
ios_base::sync_with_stdio(0);
ll n, k;
cin>>n>>k;
for( ll i =1; i <= k ; i ++ ){
cin>>a[i]>>b[i]>>a[i]>>b[i];
}
ll ans = 10000000000;
for( ll i = 1 ; i*i <= n ; i ++ ){
if( n % i == 0 ){
ll m=i, kolp1=0,kolp2=0 ;
kolp1=((n*n)/(m*m))/2+((n*n)/(m*m))%2;
kolp2=((n*n)/(m*m))/2;
kolp1=kolp1*m*m;
kolp2=kolp2*m*m;
//cout<<kolp1<<' '<<kolp2<<' '<<m<<endl;
for( ll x = 1; x <= k ; x ++ ){
if( (a[x]/m)%2!=0 && (b[x]/m)%2!=0 ){
kolp1--;
}
else
if( (a[x]/m)%2==0 && (b[x]/m)%2==0 ){
kolp1--;
}
else {
kolp1++;
}
if( (a[x]/m)%2==0 && (b[x]/m)%2==0 ){
kolp2--;
}
else
if( (a[x]/m)%2!=0 && (b[x]/m)%2!=0 ){
kolp2--;
}
else {
kolp2++;
}
}
// cout<<kolp1<<' '<<kolp2<<' '<<m<<endl;
ans=min(ans,min(kolp1,kolp2));
m=n/i;
if( m != n ){
kolp1=((n*n)/(m*m))/2+((n*n)/(m*m))%2;
kolp2=((n*n)/(m*m))/2;
kolp1=kolp1*m*m;
kolp2=kolp2*m*m;
/// cout<<kolp1<<' '<<kolp2<<' '<<m<<endl;
for( ll x = 1; x <= k ; x ++ ){
if( (a[x]/m)%2!=0 && (b[x]/m)%2!=0 ){
kolp1--;
}
else
if( (a[x]/m)%2==0 && (b[x]/m)%2==0 ){
kolp1--;
}
else {
kolp1++;
}
if( (a[x]/m)%2==0 && (b[x]/m)%2==0 ){
kolp2--;
}
else
if( (a[x]/m)%2!=0 && (b[x]/m)%2!=0 ){
kolp2--;
}
else {
kolp2++;
}
}
ans=min(ans,min(kolp1,kolp2));
}
}
cout<<ans;
}
/**
3 3
2 2 2 2
2 3 2 3
3 2 3 2
//////
9 10
1 1 1 1
4 4 4 4
4 5 4 5
4 6 4 6
5 4 5 4
5 5 5 5
5 6 5 6
6 4 6 4
6 5 6 5
6 6 6 6
**/
Compilation message
chessboard.cpp: In function 'int main()':
chessboard.cpp:82:1: error: expected '}' at end of input
}
^