#include <bits/stdc++.h>
#define int long long int
#define us unsigned int
#define null 0
#define mod 1000000007
#define m_p make_pair
#define f_i first
#define s_e second
#define p_b push_back
using namespace std;
int coloring(vector<int> v[],bool vis[],int color[],int s)
{
color[s]=0;
vis[s]=true;
queue<int> q;
q.push(s);
int black=0,white=1;
while(!q.empty())
{
int st=q.front();
q.pop();
for(int i=0;i<(int)v[st].size();i++)
{
int curr=v[st][i];
if(vis[curr]==false)
{
if(color[st]==0)
{
color[curr]=1;
black++;
}
else
{
color[curr]=0;
white++;
}
vis[curr]=true;
q.push(curr);
}
}
}
return max(white,black);
}
int32_t main()
{
int n,m;
cin>>n>>m;
vector<int> v[n*n];
for(int i=0;i<m;i++)
{
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
x1--,y1--,x2--,y2--;
int x=(x1*n)+y1,y=(x2*n)+y2;
v[x].push_back(y);
v[y].push_back(x);
}
bool vis[n*n];
int color[n*n];
memset(vis,false,sizeof(vis));
int ans=0;
for(int i=0;i<n*n;i++)
{
if(vis[i]==false)
{
ans+=coloring(v,vis,color,i);
}
}
cout<<ans<<endl;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgaW50IGxvbmcgbG9uZyBpbnQKI2RlZmluZSB1cyB1bnNpZ25lZCBpbnQKI2RlZmluZSBudWxsIDAKI2RlZmluZSBtb2QgMTAwMDAwMDAwNwojZGVmaW5lIG1fcCBtYWtlX3BhaXIKI2RlZmluZSBmX2kgZmlyc3QKI2RlZmluZSBzX2Ugc2Vjb25kCiNkZWZpbmUgcF9iIHB1c2hfYmFjawoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCgppbnQgY29sb3JpbmcodmVjdG9yPGludD4gdltdLGJvb2wgdmlzW10saW50IGNvbG9yW10saW50IHMpCnsKICAgIGNvbG9yW3NdPTA7CgogICAgdmlzW3NdPXRydWU7CgogICAgcXVldWU8aW50PiBxOwoKICAgIHEucHVzaChzKTsKCiAgICBpbnQgYmxhY2s9MCx3aGl0ZT0xOwoKICAgIHdoaWxlKCFxLmVtcHR5KCkpCiAgICB7CiAgICAgICAgaW50IHN0PXEuZnJvbnQoKTsKICAgICAgICBxLnBvcCgpOwoKICAgICAgICBmb3IoaW50IGk9MDtpPChpbnQpdltzdF0uc2l6ZSgpO2krKykKICAgICAgICB7CiAgICAgICAgICAgIGludCBjdXJyPXZbc3RdW2ldOwoKICAgICAgICAgICAgaWYodmlzW2N1cnJdPT1mYWxzZSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaWYoY29sb3Jbc3RdPT0wKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGNvbG9yW2N1cnJdPTE7CiAgICAgICAgICAgICAgICAgICAgYmxhY2srKzsKICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgY29sb3JbY3Vycl09MDsKICAgICAgICAgICAgICAgICAgICB3aGl0ZSsrOwogICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgIHZpc1tjdXJyXT10cnVlOwoKICAgICAgICAgICAgICAgIHEucHVzaChjdXJyKTsKCiAgICAgICAgICAgIH0KCiAgICAgICAgfQoKCiAgICB9CgogICAgcmV0dXJuIG1heCh3aGl0ZSxibGFjayk7CgoKfQoKCgppbnQzMl90IG1haW4oKQp7CgogICAgaW50IG4sbTsKCiAgICBjaW4+Pm4+Pm07CgogICAgdmVjdG9yPGludD4gdltuKm5dOwoKICAgIGZvcihpbnQgaT0wO2k8bTtpKyspCiAgICB7CiAgICAgICAgaW50IHgxLHkxLHgyLHkyOwogICAgICAgIGNpbj4+eDE+PnkxPj54Mj4+eTI7CgogICAgICAgIHgxLS0seTEtLSx4Mi0tLHkyLS07CiAgICAgICAgaW50IHg9KHgxKm4pK3kxLHk9KHgyKm4pK3kyOwoKICAgICAgICB2W3hdLnB1c2hfYmFjayh5KTsKICAgICAgICB2W3ldLnB1c2hfYmFjayh4KTsKCgogICAgfQoKICAgIGJvb2wgdmlzW24qbl07CiAgICBpbnQgY29sb3JbbipuXTsKCiAgICBtZW1zZXQodmlzLGZhbHNlLHNpemVvZih2aXMpKTsKCgogICAgaW50IGFucz0wOwoKICAgIGZvcihpbnQgaT0wO2k8bipuO2krKykKICAgIHsKICAgICAgICBpZih2aXNbaV09PWZhbHNlKQogICAgICAgIHsKICAgICAgICAgICAgYW5zKz1jb2xvcmluZyh2LHZpcyxjb2xvcixpKTsKICAgICAgICB9CiAgICB9CgogICAgY291dDw8YW5zPDxlbmRsOwoKCgoKCgoKCgoKCgoKfQo=