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;
const int N = (int)55;
const long long int oo = 1e18;
const int mod = 1e9 + 7;
struct Dinic {
  struct Edge {
    int v1, v2;
    long long int cap, flow;
    Edge *rev;
    Edge(int V1, int V2, long long int Cap, long long int Flow) {
      v1 = V1;
      v2 = V2;
      cap = Cap;
      flow = Flow;
    }
  };
  queue<int> q;
  vector<vector<Edge *>> adj;
  int n, s, t;
  const long long int oo = (long long int)1e18;
  vector<bool> blocked;
  vector<long long int> dist;
  Dinic(int N) {
    n = N;
    s = n++;
    t = n++;
    blocked.resize(n);
    dist.resize(n);
    adj.resize(n);
  }
  void add(int v1, int v2, long long int cap, long long int flow) {
    Edge *e = new Edge(v1, v2, cap, flow);
    Edge *rev = new Edge(v2, v1, 0, 0);
    rev->rev = e;
    e->rev = rev;
    adj[v1].push_back(e);
    adj[v2].push_back(rev);
  }
  bool bfs() {
    q = queue<int>();
    fill(dist.begin(), dist.end(), -1);
    dist[t] = 0;
    q.push(t);
    while (q.size()) {
      int node = q.front();
      q.pop();
      if (node == s) return true;
      for (Edge *e : adj[node]) {
        if (e->rev->cap > e->rev->flow && dist[e->v2] == -1) {
          dist[e->v2] = dist[node] + 1;
          q.push(e->v2);
        }
      }
    }
    return dist[s] != -1;
  }
  long long int dfs(int pos, long long int mi) {
    if (pos == t) return mi;
    long long int flow = 0;
    for (Edge *e : adj[pos]) {
      long long int cur = 0;
      if (!blocked[e->v2] && dist[e->v2] == dist[pos] - 1 &&
          e->cap - e->flow > 0) {
        cur = dfs(e->v2, min(mi - flow, e->cap - e->flow));
        e->flow += cur;
        e->rev->flow = -e->flow;
        flow += cur;
      }
      if (flow == mi) return flow;
    }
    blocked[pos] = flow != mi;
    return flow;
  }
  long long int flow() {
    long long int ret = 0;
    while (bfs()) {
      fill(blocked.begin(), blocked.end(), false);
      ret += dfs(s, oo);
    }
    return ret;
  }
};
int n, m;
int xa[N], xb[N], ya[N], yb[N];
vector<pair<int, int>> rows, cols;
set<int> row_ranges, col_ranges;
void print(pair<int, int> x) {
  cerr << "(" << x.first << ", " << x.second << ") ";
}
bool contains(int m1, int m2, int a, int b) {
  assert(m1 <= m2);
  return a <= m1 && m2 <= b;
}
void solve() {
  cin >> n >> m;
  if (m == 0) {
    cout << 0 << endl;
    return;
  }
  long long int tot = 0;
  for (int i = 0; i < m; ++i) {
    cin >> xa[i] >> ya[i] >> xb[i] >> yb[i];
    row_ranges.insert(xa[i]), row_ranges.insert(xb[i]);
    col_ranges.insert(ya[i]), col_ranges.insert(yb[i]);
  }
  int first = *row_ranges.begin(), last = *prev(row_ranges.end());
  for (int x : row_ranges) {
    rows.emplace_back(x, x);
    if (x == last) {
      continue;
    } else {
      int nxt = *row_ranges.upper_bound(x);
      if (x + 1 <= nxt - 1) {
        rows.emplace_back(x + 1, nxt - 1);
      }
    }
  }
  first = *col_ranges.begin(), last = *prev(col_ranges.end());
  for (int x : col_ranges) {
    cols.emplace_back(x, x);
    if (x == last) {
      break;
    } else {
      int nxt = *col_ranges.upper_bound(x);
      if (x + 1 <= nxt - 1) {
        cols.emplace_back(x + 1, nxt - 1);
      }
    }
  }
  int nr = rows.size(), nc = cols.size();
  Dinic graph(nr + nc);
  for (int i = 0; i < nr; ++i) {
    long long int weight = rows[i].second - rows[i].first + 1;
    graph.add(graph.s, i, weight, 0);
    tot += weight;
  }
  for (int i = 0; i < nc; ++i) {
    long long int weight = cols[i].second - cols[i].first + 1;
    graph.add(nr + i, graph.t, weight, 0);
    tot += weight;
  }
  for (int i = 0; i < nr; ++i) {
    for (int j = 0; j < nc; ++j) {
      bool good = false;
      for (int k = 0; k < m; ++k) {
        if (contains(rows[i].first, rows[i].second, xa[k], xb[k]) &&
            contains(cols[j].first, cols[j].second, ya[k], yb[k])) {
          good = true;
          break;
        }
      }
      if (good) {
        graph.add(i, j + nr, oo, 0);
      }
    }
  }
  cout << graph.flow() << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
  cout << fixed;
  solve();
  return 0;
}