
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
const int tx[4] = {1,0,-1,0};
const int ty[4] = {0,1,0,-1};
struct node{
bool l = false;
int a,b;
}a[N][N];
int n,m,c = 1;
bool k = 1;
bool b[N][N];
inline void dfs(int x,int y){
b[x][y] = 1;
if(!a[a[x][y].a][a[x][y].b].l){
c++,k = 1;
a[a[x][y].a][a[x][y].b].l = 0;
}
for(int i = 0; i < 4; i++){
int fx = x+tx[i];
int fy = y+ty[i];
if(!b[x][y]){
a[fx][fy].l = 1;
dfs(fx,fy);
}
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(NULL);
cin >> n >> m;
a[1][1] = {1,0,0};
int tx,ty,ta,tb;
for(int i = 1; i <= m; i++){
cin >> tx >> ty >> ta >> tb;
a[tx][ty].a = ta;
a[tx][ty].b = tb;
}
while(k){
memset(b,1,sizeof(b));
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(a[i][j].l) b[i][j] = 0;
}
}
k = 0;
dfs(1,1);
}
cout << c << endl;
return 0;
}