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;
template <typename T>
class maximum_flow {
 public:
  class edge {
   public:
    int to, rev;
    T cap, ini;
  };
  int n;
  vector<vector<edge>> ad;
  vector<int> level, itr;
  T inf;
  maximum_flow(int n) {
    this->n = n;
    inf = numeric_limits<T>::max();
    ad.resize(n);
    level.resize(n);
    itr.resize(n);
    fill(level.begin(), level.end(), -1);
  }
  void add_edge(int from, int to, T cap) {
    edge e0, e1;
    e0.to = to, e0.rev = ad[to].size(), e0.cap = cap, e0.ini = cap;
    e1.to = from, e1.rev = ad[from].size(), e1.cap = 0, e1.ini = 0;
    ad[from].push_back(e0);
    ad[to].push_back(e1);
  }
  void bfs(int s) {
    fill(level.begin(), level.end(), -1);
    level[s] = 0;
    queue<int> que;
    que.push(s);
    while (que.size()) {
      int v = que.front();
      que.pop();
      for (int i = 0; i < ad[v].size(); i++) {
        edge &e = ad[v][i];
        if (e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          que.push(e.to);
        }
      }
    }
  }
  T dfs(int v, int t, T f) {
    if (v == t) return f;
    for (; itr[v] < ad[v].size(); itr[v]++) {
      edge &e = ad[v][itr[v]];
      if (e.cap > 0 && level[v] < level[e.to]) {
        T d = dfs(e.to, t, min(f, e.cap));
        if (d > 0) {
          e.cap -= d;
          ad[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
  T flow(int s, int t) {
    T res = 0, f = 0;
    bfs(s);
    while (level[t] >= 0) {
      fill(itr.begin(), itr.end(), 0);
      f = dfs(s, t, inf);
      while (f > 0) {
        res += f;
        f = dfs(s, t, inf);
      }
      bfs(s);
    }
    return res;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  int m;
  cin >> n >> m;
  using P = pair<long long, long long>;
  vector<pair<P, P>> a(m);
  vector<long long> xs, ys;
  for (int i = 0; i < m; i++) {
    long long x0, y0, x1, y1;
    cin >> x0 >> y0 >> x1 >> y1;
    x1++;
    y1++;
    a[i] = make_pair(make_pair(x0, x1), make_pair(y0, y1));
    xs.push_back(x0);
    xs.push_back(x1);
    ys.push_back(y0);
    ys.push_back(y1);
  }
  sort(xs.begin(), xs.end());
  sort(ys.begin(), ys.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  ys.erase(unique(ys.begin(), ys.end()), ys.end());
  int nl = (int)xs.size();
  int nr = (int)ys.size();
  vector<P> left, right;
  for (int i = 1; i < nl; i++) {
    left.push_back(make_pair(xs[i - 1], xs[i]));
  }
  for (int i = 1; i < nr; i++) {
    right.push_back(make_pair(ys[i - 1], ys[i]));
  }
  maximum_flow<long long> mf(nl + nr + 2);
  int from = nl + nr;
  int to = from + 1;
  for (int i = 0; i < nl; i++) {
    for (int j = 0; j < nr; j++) {
      for (int k = 0; k < m; k++) {
        if (left[i].first < a[k].first.first ||
            left[i].second > a[k].first.second)
          continue;
        if (right[j].first < a[k].second.first ||
            right[j].second > a[k].second.second)
          continue;
        mf.add_edge(i, nl + j, 1LL << 55);
        break;
      }
    }
  }
  for (int i = 0; i < nl; i++) {
    mf.add_edge(from, i, left[i].second - left[i].first);
  }
  for (int i = 0; i < nr; i++) {
    mf.add_edge(nl + i, to, right[i].second - right[i].first);
  }
  long long res = mf.flow(from, to);
  cout << res << "\n";
  return 0;
}