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 ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using vpdd = vector<pdd>;
using vvpdd = vector<vpdd>;
template <typename T>
void ckmin(T& a, const T& b) {
  a = min(a, b);
}
template <typename T>
void ckmax(T& a, const T& b) {
  a = max(a, b);
}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
namespace __input {
template <class T1, class T2>
void re(pair<T1, T2>& p);
template <class T>
void re(vector<T>& a);
template <class T, size_t SZ>
void re(array<T, SZ>& a);
template <class T>
void re(T& x) {
  cin >> x;
}
void re(double& x) {
  string t;
  re(t);
  x = stod(t);
}
template <class Arg, class... Args>
void re(Arg& first, Args&... rest) {
  re(first);
  re(rest...);
}
template <class T1, class T2>
void re(pair<T1, T2>& p) {
  re(p.first, p.second);
}
template <class T>
void re(vector<T>& a) {
  for (int i = 0; i < (int((a).size())); i++) re(a[i]);
}
template <class T, size_t SZ>
void re(array<T, SZ>& a) {
  for (int i = 0; i < (SZ); i++) re(a[i]);
}
}  // namespace __input
using namespace __input;
namespace __output {
template <class T1, class T2>
void pr(const pair<T1, T2>& x);
template <class T, size_t SZ>
void pr(const array<T, SZ>& x);
template <class T>
void pr(const vector<T>& x);
template <class T>
void pr(const set<T>& x);
template <class T1, class T2>
void pr(const map<T1, T2>& x);
template <class T>
void pr(const T& x) {
  cout << x;
}
template <class Arg, class... Args>
void pr(const Arg& first, const Args&... rest) {
  pr(first);
  pr(rest...);
}
template <class T1, class T2>
void pr(const pair<T1, T2>& x) {
  pr("{", x.first, ", ", x.second, "}");
}
template <class T, bool pretty = true>
void prContain(const T& x) {
  if (pretty) pr("{");
  bool fst = 1;
  for (const auto& a : x) pr(!fst ? pretty ? ", " : " " : "", a), fst = 0;
  if (pretty) pr("}");
}
template <class T>
void pc(const T& x) {
  prContain<T, false>(x);
  pr("\n");
}
template <class T, size_t SZ>
void pr(const array<T, SZ>& x) {
  prContain(x);
}
template <class T>
void pr(const vector<T>& x) {
  prContain(x);
}
template <class T>
void pr(const set<T>& x) {
  prContain(x);
}
template <class T1, class T2>
void pr(const map<T1, T2>& x) {
  prContain(x);
}
void ps() { pr("\n"); }
template <class Arg>
void ps(const Arg& first) {
  pr(first);
  ps();
}
template <class Arg, class... Args>
void ps(const Arg& first, const Args&... rest) {
  pr(first, " ");
  ps(rest...);
}
}  // namespace __output
using namespace __output;
namespace __algorithm {
template <typename T>
void dedup(vector<T>& v) {
  sort((v).begin(), (v).end());
  v.erase(unique((v).begin(), (v).end()), v.end());
}
template <typename T>
typename vector<T>::iterator find(vector<T>& v, const T& x) {
  auto it = lower_bound((v).begin(), (v).end(), x);
  return it != v.end() && *it == x ? it : v.end();
}
template <typename T>
size_t index(vector<T>& v, const T& x) {
  auto it = find(v, x);
  assert(it != v.end() && *it == x);
  return it - v.begin();
}
template <typename C, typename T>
vector<T> prefixes(const C& v, T zero) {
  vector<T> res(int((v).size()) + 1, zero);
  for (int i = 0; i < (int((v).size())); i++) res[i + 1] = res[i] + v[i];
  return res;
}
template <typename C, typename T>
vector<T> suffixes(const C& v, T zero) {
  vector<T> res(int((v).size()) + 1, zero);
  for (int i = (int((v).size())) - 1; i >= 0; i--) res[i] = v[i] + res[i + 1];
  return res;
}
}  // namespace __algorithm
using namespace __algorithm;
struct monostate {
  friend istream& operator>>(istream& is,
                             const __attribute__((unused)) monostate& ms) {
    return is;
  }
  friend ostream& operator<<(ostream& os,
                             const __attribute__((unused)) monostate& ms) {
    return os;
  }
} ms;
template <typename W = monostate>
struct wedge {
  int u, v, i;
  W w;
  wedge<W>(int _u = -1, int _v = -1, int _i = -1) : u(_u), v(_v), i(_i) {}
  int operator[](int loc) const { return u ^ v ^ loc; }
  friend void re(wedge& e) {
    re(e.u, e.v, e.w);
    --e.u, --e.v;
  }
  friend void pr(const wedge& e) { pr(e.u, "<-", e.w, "->", e.v); }
};
namespace __io {
void setIn(string second) { freopen(second.c_str(), "r", stdin); }
void setOut(string second) { freopen(second.c_str(), "w", stdout); }
void setIO(string second = "") {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(15);
  if (int((second).size())) {
    setIn(second + ".in"), setOut(second + ".out");
  }
}
}  // namespace __io
using namespace __io;
template <typename F>
struct dinic {
  static const F inf = numeric_limits<F>::max();
  int V;
  vvi adj;
  vi dest;
  vector<F> cap;
  dinic(int V = 0) : V(V) { adj.resize(V); }
  void __arc(int u, int v, F c) {
    adj[u].push_back(dest.size());
    dest.push_back(v);
    cap.push_back(c);
  }
  void arc(int u, int v, F c) {
    __arc(u, v, c);
    __arc(v, u, F(0));
  }
  bool bfs(int second, int t, vi& level, vector<F>& flow) const {
    level = vi(V, -1);
    level[second] = 0;
    for (queue<int> q({second}); !q.empty(); q.pop()) {
      int u = q.front();
      for (int e : adj[u]) {
        if (level[dest[e]] == -1 && flow[e] < cap[e]) {
          level[dest[e]] = level[u] + 1;
          q.push(dest[e]);
        }
      }
    }
    return level[t] != -1;
  }
  F augment(int second, int t, vi& level, vector<F>& flow, vi& inx,
            F cur) const {
    if (second == t) return cur;
    for (int e; inx[second] < adj[second].size(); inx[second]++) {
      e = adj[second][inx[second]];
      if (level[dest[e]] != level[second] + 1) continue;
      if (flow[e] == cap[e]) continue;
      F incr =
          augment(dest[e], t, level, flow, inx, min(cur, cap[e] - flow[e]));
      if (incr > F(0)) {
        flow[e] += incr;
        flow[e ^ 1] -= incr;
        return incr;
      }
    }
    return F(0);
  }
  tuple<F, vector<F>> max_flow(int second, int t) const {
    assert(second != t);
    F res(0);
    vector<F> flow(cap.size());
    for (vi level; bfs(second, t, level, flow);) {
      for (vi inx(V, 0); F incr = augment(second, t, level, flow, inx, inf);)
        res += incr;
    }
    return make_tuple(res, flow);
  }
};
int main() {
  setIO();
  int N, M;
  re(N, M);
  vi allX, allY;
  struct rect {
    int x1, y1, x2, y2;
  };
  vector<rect> rc(M);
  for (int i = 0; i < (M); i++) {
    auto& r = rc[i];
    re(r.x1, r.y1, r.x2, r.y2);
    allX.push_back(r.x1);
    allX.push_back(++r.x2);
    allY.push_back(r.y1);
    allY.push_back(++r.y2);
  }
  dedup(allX);
  dedup(allY);
  const int SRC = 0, XL = 1, YL = XL + int((allX).size()),
            SNK = YL + int((allY).size());
  dinic<ll> g(SNK + 1);
  for (int i = 0; i < (int((allX).size()) - 1); i++) {
    g.arc(SRC, XL + i, allX[i + 1] - allX[i]);
  }
  for (int i = 0; i < (int((allY).size()) - 1); i++) {
    g.arc(YL + i, SNK, allY[i + 1] - allY[i]);
  }
  vector<vb> conn(int((allX).size()), vb(int((allY).size()), false));
  for (int ri = 0; ri < (M); ri++) {
    auto& r = rc[ri];
    for (int i = 0; i < (int((allX).size()) - 1); i++) {
      if (r.x1 <= allX[i] && r.x2 >= allX[i + 1]) {
        for (int j = 0; j < (int((allY).size()) - 1); j++) {
          if (r.y1 <= allY[j] && r.y2 >= allY[j + 1]) {
            if (!conn[i][j]) {
              conn[i][j] = true;
              g.arc(XL + i, YL + j, LLONG_MAX / 8);
            }
          }
        }
      }
    }
  }
  ps(get<0>(g.max_flow(SRC, SNK)));
  return 0;
}