Problem: There is a square grid of size n × n. Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It costs min(h, w) to color a rectangle of size h × w. You are to make all cells white for minimum total cost.

The square is large, so we give it to you in a compressed way. The set of black cells is the union of m rectangles.

Input

The first line contains two integers n and m (1 ≤ n ≤ 10^{9}, 0 ≤ m ≤ 50) — the size of the square grid and the number of black rectangles.

Each of the next m lines contains 4 integers x_{i1} y_{i1} x_{i2} y_{i2} (1 ≤ x_{i1} ≤ x_{i2} ≤ n, 1 ≤ y_{i1} ≤ y_{i2} ≤ n) — the coordinates of the bottom-left and the top-right corner cells of the i-th black rectangle.

The rectangles may intersect.

Output

Print a single integer — the minimum total cost of painting the whole square in white.

Examples

Input


10 2
4 1 5 10
1 4 10 5


Output


4


Input


7 6
2 1 2 1
4 2 4 3
2 5 2 5
2 3 5 3
1 2 1 2
3 2 5 3


Output


3

Note

The examples and some of optimal solutions are shown on the pictures below.

<image>

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
long long inf = 1e18;
class network_flow {
 private:
  int N;
  struct edge {
    int to;
    long long cap;
    int rev;
  };
  vector<vector<edge>> G;
  vector<int> level, iter;
  void bfs(int s) {
    for (int i = 0; i <= N; i++) level[i] = -1;
    queue<int> Q;
    level[s] = 0;
    Q.push(s);
    while (!Q.empty()) {
      int v = Q.front();
      Q.pop();
      for (int i = 0; i < G[v].size(); i++) {
        edge &e = G[v][i];
        if (e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          Q.push(e.to);
        }
      }
    }
  }
  long long dfs(int v, int t, long long f) {
    if (v == t) return f;
    for (int &i = iter[v]; i < G[v].size(); i++) {
      edge &e = G[v][i];
      if (level[v] < level[e.to] && e.cap > 0) {
        long long d = dfs(e.to, t, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

 public:
  network_flow(int n) {
    N = n;
    G = vector<vector<edge>>(N + 1);
    level = iter = vector<int>(N + 1);
  }
  void add_edge(int from, int to, long long cap) {
    G[from].push_back((edge){to, cap, (int)G[to].size()});
    G[to].push_back((edge){from, 0, (int)G[from].size() - 1});
  }
  long long max_flow(int s, int t) {
    long long flow = 0;
    for (;;) {
      bfs(s);
      if (level[t] < 0) return flow;
      for (int i = 0; i <= N; i++) iter[i] = 0;
      long long f;
      while ((f = dfs(s, t, inf)) > 0) flow += f;
    }
  }
};
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> mx, my;
  vector<int> x1(M), x2(M), y1(M), y2(M);
  for (int i = 0; i < M; i++) {
    cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
    mx[x1[i]] = 1;
    mx[x2[i] + 1] = 1;
    my[y1[i]] = 1;
    my[y2[i] + 1] = 1;
  }
  vector<int> X, Y;
  for (auto x : mx) X.push_back(x.first);
  for (auto y : my) Y.push_back(y.first);
  X.push_back(N + 1);
  Y.push_back(N + 1);
  int n = X.size() - 1, m = Y.size() - 1;
  mx.clear();
  my.clear();
  for (int i = 0; i < n; i++) mx[X[i]] = i + 1;
  for (int i = 0; i < m; i++) my[Y[i]] = i + 1;
  vector<vector<int>> S(n + 1, vector<int>(m + 1, 0));
  for (int i = 0; i < M; i++) {
    int X1 = mx[x1[i]], X2 = mx[x2[i] + 1], Y1 = my[y1[i]], Y2 = my[y2[i] + 1];
    S[X1][Y1]++;
    S[X2][Y1]--;
    S[X1][Y2]--;
    S[X2][Y2]++;
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) S[i][j] += S[i][j - 1];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) S[i][j] += S[i - 1][j];
  network_flow flow(n + m + 2);
  for (int i = 0; i < n; i++) flow.add_edge(0, i + 1, X[i + 1] - X[i]);
  for (int i = 0; i < m; i++)
    flow.add_edge(n + i + 1, n + m + 1, Y[i + 1] - Y[i]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (S[i][j] >= 1) {
        flow.add_edge(i, n + j, inf);
      }
  cout << flow.max_flow(0, n + m + 1) << endl;
}