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>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
bool dbg = 0;
clock_t start_time = clock();
void bad(string mes = "Impossible") {
  cout << mes;
  exit(0);
}
void bad(int mes) {
  cout << mes;
  exit(0);
}
template <typename T>
string bin(T x, int st = 2) {
  string ans = "";
  while (x > 0) {
    ans += char('0' + x % st);
    x /= st;
  }
  reverse(ans.begin(), ans.end());
  return ans.empty() ? "0" : ans;
}
mt19937_64 mt_rand(chrono::system_clock::now().time_since_epoch().count());
template <typename T1, typename T2>
inline bool upmax(T1& a, T2 b) {
  return (a < b ? (a = b, true) : false);
}
template <typename T1, typename T2>
inline bool upmin(T1& a, T2 b) {
  return (b < a ? (a = b, true) : false);
}
inline int popcount(int x) {
  int count = 0;
  __asm__ volatile("POPCNT %1, %0;" : "=r"(count) : "r"(x) :);
  return count;
}
template <typename T>
T input() {
  T ans = 0, m = 1;
  char c = ' ';
  while (!((c >= '0' && c <= '9') || c == '-')) {
    c = getchar();
  }
  if (c == '-') m = -1, c = getchar();
  while (c >= '0' && c <= '9') {
    ans = ans * 10 + (c - '0'), c = getchar();
  }
  return ans * m;
}
template <typename T>
T gcd(T a, T b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
template <typename T>
void read(T& a) {
  a = input<T>();
}
template <typename T>
void read(T& a, T& b) {
  read(a), read(b);
}
template <typename T>
void read(T& a, T& b, T& c) {
  read(a, b), read(c);
}
template <typename T>
void read(T& a, T& b, T& c, T& d) {
  read(a, b), read(c, d);
}
const int inf = 1e9 + 20;
const short short_inf = 3e4 + 20;
const long double eps = 1e-12;
const int maxn = (int)1e5 + 450, base = 1e9 + 7;
const long long llinf = 2e18 + 5;
template <typename T>
struct Flow {
  vector<vector<T> > first, c;
  vector<long long> d, lastNotUsed;
  const T inf = (T)1e18;
  int second, t, n;
  Flow() {}
  Flow(int _n, int second, int t) : second(second), t(t) {
    n = _n;
    c = first = vector<vector<T> >(n, vector<T>(n, 0));
  }
  void addEdge(int u, int v, T e) { c[u][v] += e; }
  bool bfs() {
    queue<int> q;
    d = vector<T>(n, -1);
    q.push(second);
    d[second] = 0;
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (int i = 0; i < n; i++) {
        if (d[i] == -1 && first[v][i] < c[v][i]) {
          d[i] = d[v] + 1;
          q.push(i);
        }
      }
    }
    return d[t] != -1;
  }
  T dfs(int v, T flow) {
    if (v == t || flow == 0) return flow;
    for (T& i = lastNotUsed[v]; i < n; i++) {
      if (d[i] == d[v] + 1) {
        T pushed = dfs(i, min(flow, c[v][i] - first[v][i]));
        if (pushed) {
          first[v][i] += pushed;
          first[i][v] -= pushed;
          return pushed;
        }
      }
    }
    return 0;
  }
  T dinic() {
    T flow = 0;
    while (1) {
      if (!bfs()) break;
      lastNotUsed = vector<T>(n, 0);
      while (T curFlow = dfs(second, inf)) flow += curFlow;
    }
    return flow;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  if (!m) bad(0);
  vector<tuple<int, int, int, int> > e;
  vector<int> a, b;
  for (int i = 0; i < m; i++) {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    e.emplace_back(x1, y1, x2, y2);
    a.push_back(x1);
    a.push_back(x2 + 1);
    b.push_back(y1);
    b.push_back(y2 + 1);
  }
  a.push_back(1);
  a.push_back(n + 1);
  b.push_back(1);
  b.push_back(n + 1);
  sort((a).begin(), (a).end());
  a.resize(unique((a).begin(), (a).end()) - a.begin());
  sort((b).begin(), (b).end());
  b.resize(unique((b).begin(), (b).end()) - b.begin());
  int cnt;
  int cntl = a.size() - 1;
  Flow<long long> mf(cnt = (a.size() - 1 + b.size() - 1 + 2), 0, 1);
  for (auto& [x1, y1, x2, y2] : e) {
    for (int i = 0; i + 1 < a.size(); i++) {
      if (a[i] >= x1 && a[i + 1] - 1 <= x2) {
        for (int j = 0; j + 1 < b.size(); j++) {
          if (b[j] >= y1 && b[j + 1] - 1 <= y2) {
            mf.addEdge(i + 2, j + 2 + cntl, inf);
          }
        }
      }
    }
  }
  for (int i = 0; i + 1 < a.size(); i++) {
    mf.addEdge(0, i + 2, a[i + 1] - a[i]);
  }
  for (int j = 0; j + 1 < b.size(); j++) {
    mf.addEdge(j + 2 + cntl, 1, b[j + 1] - b[j]);
  }
  cout << mf.dinic();
  return 0;
}