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;
using namespace chrono;
template <class T1, class T2>
istream &operator>>(istream &in, pair<T1, T2> &P) {
  in >> P.first >> P.second;
  return in;
}
template <class T>
istream &operator>>(istream &in, vector<T> &arr) {
  for (auto &x : arr) in >> x;
  return in;
}
template <class T>
ostream &operator<<(ostream &out, vector<T> &arr) {
  for (auto &x : arr) out << x << ' ';
  cout << "\n";
  return out;
}
template <class T>
void print(vector<T> arr) {
  cout << "-------------------------------------------------------------"
          "\nArray: ";
  cout << arr;
  cout << "-------------------------------------------------------------\n";
}
template <class T>
void print(vector<vector<T>> arr) {
  cout << "-------------------------------------------------------------"
          "\nArray: \n";
  for (auto x : arr) {
    cout << " ";
    cout << x;
  }
  cout << "-------------------------------------------------------------\n";
}
template <class T1, class T2>
void print(vector<pair<T1, T2>> arr) {
  cout << "-------------------------------------------------------------"
          "\nArray: ";
  for (auto x : arr) {
    cout << "(" << x.first << ", " << x.second << ") ";
  }
  cout << "\n-------------------------------------------------------------\n";
}
template <class T1, class T2>
void print(vector<vector<pair<T1, T2>>> arr) {
  cout << "-------------------------------------------------------------"
          "\nArray: \n";
  for (auto x : arr) {
    cout << " ";
    for (auto y : x) {
      cout << "(" << y.first << ", " << y.second << ") ";
    }
    cout << "\n";
  }
  cout << "-------------------------------------------------------------\n";
}
template <class T>
struct flownetwork {
  static constexpr T eps = (T)1e-9;
  int n;
  vector<vector<int>> adj;
  struct edge {
    int from, to;
    T capacity, flow;
  };
  vector<edge> edge;
  int source, sink;
  T flow;
  flownetwork(int n, int source, int sink) : n(n), source(source), sink(sink) {
    adj.resize(n);
    flow = 0;
  }
  void clear() {
    for (auto &e : edge) {
      e.flow = 0;
    }
    flow = 0;
  }
  int insert(int from, int to, T fcap, T bcap) {
    int ind = (int(edge.size()));
    adj[from].push_back(ind);
    edge.push_back({from, to, fcap, 0});
    adj[to].push_back(ind + 1);
    edge.push_back({to, from, bcap, 0});
    return ind;
  }
};
template <class T>
struct dinic {
  static constexpr T INF = numeric_limits<T>::max();
  flownetwork<T> &g;
  vector<int> ptr, level, q;
  dinic(flownetwork<T> &_g) : g(_g) {
    ptr.resize(g.n), level.resize(g.n), q.resize(g.n);
  }
  bool bfs() {
    fill(level.begin(), level.end(), -1);
    q[0] = g.sink;
    level[g.sink] = 0;
    int beg = 0, end = 1;
    while (beg < end) {
      int i = q[beg++];
      for (auto ind : g.adj[i]) {
        auto &e = g.edge[ind];
        auto &re = g.edge[ind ^ 1];
        if (re.capacity - re.flow > g.eps && level[e.to] == -1) {
          level[e.to] = level[i] + 1;
          if (e.to == g.source) {
            return true;
          }
          q[end++] = e.to;
        }
      }
    }
    return false;
  }
  T dfs(int u, T w) {
    if (u == g.sink) {
      return w;
    }
    int &j = ptr[u];
    while (j >= 0) {
      int ind = g.adj[u][j];
      auto &e = g.edge[ind];
      if (e.capacity - e.flow > g.eps && level[e.to] == level[u] - 1) {
        T F = dfs(e.to, min(e.capacity - e.flow, w));
        if (F > g.eps) {
          g.edge[ind].flow += F;
          g.edge[ind ^ 1].flow -= F;
          return F;
        }
      }
      j--;
    }
    return 0;
  }
  T max_flow() {
    while (bfs()) {
      for (int i = 0; i < g.n; i++) {
        ptr[i] = (int(g.adj[i].size())) - 1;
      }
      T sum = 0;
      while (1) {
        T add = dfs(g.source, INF);
        if (add <= g.eps) {
          break;
        }
        sum += add;
      }
      if (sum <= g.eps) {
        break;
      }
      g.flow += sum;
    }
    return g.flow;
  }
  vector<bool> min_cut() {
    max_flow();
    vector<bool> res(g.n);
    for (int i = 0; i < g.n; i++) {
      res[i] = (level[i] != -1);
    }
    return res;
  }
};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<tuple<int, int, int, int>> a(m);
  vector<int> X{0, n}, Y{0, n};
  const long long INF = 2e18;
  for (auto &[lx, ly, ux, uy] : a) {
    cin >> lx >> ly >> ux >> uy, lx--, ly--;
    X.push_back(lx), Y.push_back(ly), X.push_back(ux), Y.push_back(uy);
  }
  sort(X.begin(), X.end()), sort(Y.begin(), Y.end()),
      X.resize(unique(X.begin(), X.end()) - X.begin()),
      Y.resize(unique(Y.begin(), Y.end()) - Y.begin());
  int nx = (int(X.size())) - 1, ny = (int(Y.size())) - 1;
  int source = nx + ny, sink = nx + ny + 1;
  flownetwork<long long> g(nx + ny + 2, source, sink);
  for (int i = 0; i < nx; i++) {
    g.insert(source, i, X[i + 1] - X[i], 0);
  }
  for (int i = 0; i < ny; i++) {
    g.insert(nx + i, sink, Y[i + 1] - Y[i], 0);
  }
  for (int i = 0; i < nx; i++) {
    for (int j = 0; j < ny; j++) {
      auto pred = [&](const tuple<int, int, int, int> &arg) {
        auto [lx, ly, ux, uy] = arg;
        return lx <= X[i] && X[i + 1] <= ux && ly <= Y[j] && Y[j + 1] <= uy;
      };
      if (any_of(a.begin(), a.end(), pred)) {
        g.insert(i, nx + j, INF, 0);
      }
    }
  }
  dinic<long long> d(g);
  cout << d.max_flow();
  return 0;
}