// Arup Guha
// 3/23/2016
// Solution to 2015 December Silver USACO Contest Problem: Switching on the Lights (lightson).

import java.util.*;
import java.io.*;

public class lightson {

    // Directions of movement in grid.
    final public static int[] DX = {-1,0,0,1};
    final public static int[] DY = {0,-1,1,0};

    public static int n;

	public static void main(String[] args) throws Exception {

        // Read in data.
		BufferedReader stdin = new BufferedReader(new FileReader("lightson.in"));
		StringTokenizer tok = new StringTokenizer(stdin.readLine());
		n = Integer.parseInt(tok.nextToken());
		int lights = Integer.parseInt(tok.nextToken());
		ArrayList[][] grid = new ArrayList[n][n];
		for (int i=0; i<n*n; i++)
            grid[i/n][i%n] = new ArrayList<Integer>();

        // Add each light, store switch location as a single integer in base n.
        for (int i=0; i<lights; i++) {
            tok = new StringTokenizer(stdin.readLine());
            int r1 = Integer.parseInt(tok.nextToken()) - 1;
            int c1 = Integer.parseInt(tok.nextToken()) - 1;
            int r2 = Integer.parseInt(tok.nextToken()) - 1;
            int c2 = Integer.parseInt(tok.nextToken()) - 1;
            grid[r1][c1].add(r2*n+c2);
        }

        // Set up BFS.
        boolean[][] visited = new boolean[n][n];
        boolean[][] on = new boolean[n][n];
        on[0][0] = true;
        LinkedList<Integer> q = new LinkedList<Integer>();
        q.offer(0);
        visited[0][0] = true;

        // Run BFS here.
        while (q.size() > 0) {

            // Get next room in queue.
            int cur = q.poll();
            int x = cur/n;
            int y = cur%n;

            // Greedily turn on all the rooms it's connected to.
            for (int i=0; i<grid[x][y].size(); i++) {
                int next = ((ArrayList<Integer>)grid[x][y]).get(i);
                on[next/n][next%n] = true;

                // This is tricky, go ahead and add to the queue anyone who touches a square
                // that is lit.
                for (int j=0; j<DX.length; j++) {
                    int nx = next/n + DX[j];
                    int ny = next%n + DY[j];
                    if (inbounds(nx, ny) && visited[nx][ny] && !visited[next/n][next%n]) {
                        q.offer(next);
                        visited[next/n][next%n] = true;
                        break;
                    }
                }
            }

            // Now, enqueue neighbors (places we've never been but are on).
            for (int i=0; i<DX.length; i++) {
                if (inbounds(x+DX[i], y+DY[i]) && !visited[x+DX[i]][y+DY[i]] && on[x+DX[i]][y+DY[i]]) {
                    visited[x+DX[i]][y+DY[i]] = true;
                    q.offer(n*(x+DX[i]) + y+DY[i]);
                }
            }
        }

        // Add up all rooms that are on.
        int res = 0;
        for (int i=0; i<n*n; i++)
            if (on[i/n][i%n])
                res++;
		// Answer each query by using subtraction on cumulative frequency arrays.
		FileWriter fout = new FileWriter(new File("lightson.out"));
        fout.write(res+"\n");
		fout.close();
	}

	public static boolean inbounds(int x, int y) {
        return x >= 0 && x < n && y >= 0 && y < n;
	}
}
