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 TH>
void _dbg(const char* sdbg, TH h) {
  cerr << sdbg << "=" << h << "\n";
}
template <typename TH, typename... TA>
void _dbg(const char* sdbg, TH h, TA... t) {
  while (*sdbg != ',') {
    cerr << *sdbg++;
  }
  cerr << "=" << h << ",";
  _dbg(sdbg + 1, t...);
}
template <class C>
void mini(C& a4, C b4) {
  a4 = min(a4, b4);
}
template <class C>
void maxi(C& a4, C b4) {
  a4 = max(a4, b4);
}
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> pair) {
  return out << "(" << pair.first << ", " << pair.second << ")";
}
template <class A, class B, class C>
struct Triple {
  A first;
  B second;
  C third;
  bool operator<(const Triple& t) const {
    if (first != t.first) return first < t.first;
    if (second != t.second) return second < t.second;
    return third < t.third;
  }
};
template <class T>
void ResizeVec(T&, vector<long long>) {}
template <class T>
void ResizeVec(vector<T>& vec, vector<long long> sz) {
  vec.resize(sz[0]);
  sz.erase(sz.begin());
  if (sz.empty()) {
    return;
  }
  for (T& v : vec) {
    ResizeVec(v, sz);
  }
}
template <class A, class B, class C>
ostream& operator<<(ostream& out, Triple<A, B, C> t) {
  return out << "(" << t.first << ", " << t.second << ", " << t.third << ")";
}
template <class T>
ostream& operator<<(ostream& out, vector<T> vec) {
  out << "(";
  for (auto& v : vec) out << v << ", ";
  return out << ")";
}
template <class T>
ostream& operator<<(ostream& out, set<T> vec) {
  out << "(";
  for (auto& v : vec) out << v << ", ";
  return out << ")";
}
template <class L, class R>
ostream& operator<<(ostream& out, map<L, R> vec) {
  out << "(";
  for (auto& v : vec) out << v << ", ";
  return out << ")";
}
struct Dinic {
  struct Edge {
    long long v, c, inv;
  };

 public:
  Dinic() { n = -1; }
  void AddEdge(long long a, long long b, long long cap, long long bi_dir) {
    if (n < max(a, b)) {
      n = max(n, max(a, b));
      ResizeVectors();
    }
    e_orig[a].push_back(Edge{b, cap, ((long long)(e_orig[b]).size())});
    e_orig[b].push_back(
        Edge{a, bi_dir * cap, ((long long)(e_orig[a]).size()) - 1});
  }
  long long MaxFlow(long long s, long long t) {
    if (t > n || s > n) {
      n = max(s, t);
      ResizeVectors();
    }
    e = e_orig;
    long long result = 0;
    while (Bfs(s, t)) {
      for (long long i = 0; i <= n; i++) {
        beg[i] = 0;
      }
      result += Dfs(s, t, kInf);
    }
    return result;
  }
  vector<bool> MinCut(long long s, long long t) {
    assert(!Bfs(s, t));
    vector<bool> res(n + 1);
    for (long long i = 0; i <= n; i++) {
      res[i] = (dis[i] <= n);
    }
    return res;
  }
  vector<pair<long long, long long>> EdgeCut(long long s, long long t) {
    vector<bool> left_part = MinCut(s, t);
    vector<pair<long long, long long>> cut;
    for (long long v = 0; v <= n; v++) {
      for (auto edge : e_orig[v]) {
        if (edge.c != 0 && left_part[v] && !left_part[edge.v]) {
          cut.push_back({v, edge.v});
        }
      }
    }
    return cut;
  }

 private:
  long long n;
  vector<vector<Edge>> e_orig, e;
  vector<long long> dis, beg;
  bool Bfs(long long s, long long t) {
    for (long long i = 0; i <= n; i++) {
      dis[i] = n + 1;
    }
    dis[s] = 0;
    vector<long long> que;
    que.push_back(s);
    for (long long i = 0; i < ((long long)(que).size()); i++) {
      long long v = que[i];
      for (auto edge : e[v]) {
        long long nei = edge.v;
        if (edge.c && dis[nei] > dis[v] + 1) {
          dis[nei] = dis[v] + 1;
          que.push_back(nei);
          if (nei == t) {
            return true;
          }
        }
      }
    }
    return false;
  }
  long long Dfs(long long v, long long t, long long min_cap) {
    long long result = 0;
    if (v == t || min_cap == 0) {
      return min_cap;
    }
    for (long long& i = beg[v]; i < ((long long)(e[v]).size()); i++) {
      long long nei = e[v][i].v;
      long long c = e[v][i].c;
      if (dis[nei] == dis[v] + 1 && c > 0) {
        long long flow_here = Dfs(nei, t, min(min_cap, c));
        result += flow_here;
        min_cap -= flow_here;
        e[v][i].c -= flow_here;
        e[nei][e[v][i].inv].c += flow_here;
      }
      if (min_cap == 0) {
        break;
      }
    }
    return result;
  }
  void ResizeVectors() {
    e_orig.resize(n + 2);
    beg.resize(n + 2);
    dis.resize(n + 2);
  }

 public:
  static const long long kInf = 1e18;
};
void Numeruj(map<long long, long long>& mapka) {
  long long nxt = 1;
  for (auto& p : mapka) {
    p.second = nxt;
    nxt++;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  if (0) cout << fixed << setprecision(10);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  map<long long, long long> xs, ys;
  vector<vector<long long>> rects;
  for (long long i = (1); i <= (m); ++i) {
    long long x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    xs[x1] = 1;
    xs[x2 + 1] = 1;
    ys[y1] = 1;
    ys[y2 + 1] = 1;
    rects.push_back({x1, y1, x2, y2});
  }
  Numeruj(xs);
  Numeruj(ys);
  (xs);
  (ys);
  Dinic gr;
  long long s = 0, t = 4 * m + 3;
  long long prv = 0;
  for (auto p : xs) {
    gr.AddEdge(s, p.second, p.first - prv, 0);
    prv = p.first;
  }
  prv = 0;
  for (auto p : ys) {
    gr.AddEdge(p.second + 2 * m, t, p.first - prv, 0);
    prv = p.first;
  }
  for (auto p : xs) {
    for (auto q : ys) {
      for (auto r : rects) {
        if (r[0] <= p.first && p.first <= r[2] && r[1] <= q.first &&
            q.first <= r[3]) {
          (p.first, q.first);
          gr.AddEdge(p.second + 1, q.second + 2 * m + 1, Dinic::kInf, 0);
          break;
        }
      }
    }
  }
  cout << gr.MaxFlow(s, t) << endl;
  return 0;
}