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;
template <class t, class u>
void chmax(t& first, u second) {
  if (first < second) first = second;
}
template <class t, class u>
void chmin(t& first, u second) {
  if (second < first) first = second;
}
template <class t>
using vc = vector<t>;
template <class t>
using vvc = vc<vc<t>>;
using pi = pair<ll, ll>;
using vi = vc<ll>;
template <class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
  return os << "{" << p.first << "," << p.second << "}";
}
template <class t>
ostream& operator<<(ostream& os, const vc<t>& v) {
  os << "{";
  for (auto e : v) os << e << ",";
  return os << "}";
}
using uint = unsigned;
using ull = unsigned long long;
template <ll i, class T>
void print_tuple(ostream&, const T&) {}
template <ll i, class T, class H, class... Args>
void print_tuple(ostream& os, const T& t) {
  if (i) os << ",";
  os << get<i>(t);
  print_tuple<i + 1, T, Args...>(os, t);
}
template <class... Args>
ostream& operator<<(ostream& os, const tuple<Args...>& t) {
  os << "{";
  print_tuple<0, tuple<Args...>, Args...>(os, t);
  return os << "}";
}
void print(ll x, ll suc = 1) {
  cout << x;
  if (suc == 1) cout << "\n";
  if (suc == 2) cout << " ";
}
ll read() {
  ll i;
  cin >> i;
  return i;
}
vi readvi(ll n, ll off = 0) {
  vi v(n);
  for (ll i = ll(0); i < ll(n); i++) v[i] = read() + off;
  return v;
}
template <class T>
void print(const vector<T>& v, ll suc = 1) {
  for (ll i = ll(0); i < ll(v.size()); i++)
    print(v[i], i == ll(v.size()) - 1 ? suc : 2);
}
string readString() {
  string s;
  cin >> s;
  return s;
}
template <class T>
T sq(const T& t) {
  return t * t;
}
void yes(bool ex = true) {
  cout << "Yes" << endl;
  if (ex) exit(0);
}
void no(bool ex = true) {
  cout << "No" << endl;
  if (ex) exit(0);
}
constexpr ll ten(ll n) { return n == 0 ? 1 : ten(n - 1) * 10; }
const ll infLL = LLONG_MAX / 3;
const ll inf = infLL;
ll topbit(signed t) { return t == 0 ? -1 : 31 - __builtin_clz(t); }
ll topbit(ll t) { return t == 0 ? -1 : 63 - __builtin_clzll(t); }
ll popcount(signed t) { return __builtin_popcount(t); }
ll popcount(ll t) { return __builtin_popcountll(t); }
bool ispow2(ll i) { return i && (i & -i) == i; }
bool inc(ll first, ll second, ll c) { return first <= second && second <= c; }
template <class t>
void mkuni(vc<t>& v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
ll rand_int(ll l, ll r) {
  static random_device rd;
  static mt19937 gen(rd());
  return uniform_int_distribution<ll>(l, r)(gen);
}
template <class d>
struct maxflow {
  struct E {
    ll to, rev;
    d cap;
  };
  vvc<E> g;
  vi itr, lv;
  maxflow(ll n) : g(n), itr(n), lv(n) {}
  void ae(ll s, ll t, d c) {
    g[s].push_back({t, (ll)g[t].size(), c});
    g[t].push_back({s, (ll)g[s].size() - 1, 0});
  }
  void bfs(ll s) {
    fill(lv.begin(), lv.end(), -1);
    lv[s] = 0;
    queue<ll> q;
    q.push(s);
    while (q.size()) {
      ll v = q.front();
      q.pop();
      for (auto e : g[v])
        if (e.cap > 0 && lv[e.to] == -1) {
          lv[e.to] = lv[v] + 1;
          q.push(e.to);
        }
    }
  }
  d dfs(ll v, ll t, d f) {
    if (v == t) return f;
    d res = 0;
    for (ll& i = itr[v]; i < (ll)g[v].size(); i++) {
      E& e = g[v][i];
      if (e.cap > 0 && lv[e.to] == lv[v] + 1) {
        d first = dfs(e.to, t, min(f, e.cap));
        if (first > 0) {
          e.cap -= first;
          g[e.to][e.rev].cap += first;
          res += first;
          f -= first;
          if (f <= 0) break;
        }
      }
    }
    return res;
  }
  d calc(ll s, ll t) {
    d f = 0;
    while (1) {
      bfs(s);
      if (lv[t] == -1) return f;
      fill(itr.begin(), itr.end(), 0);
      f += dfs(s, t, 1e9);
    }
  }
};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
  ll n, m;
  cin >> n >> m;
  if (m == 0) {
    cout << 0 << endl;
    return 0;
  }
  vi xs, ys;
  using R = tuple<ll, ll, ll, ll>;
  vc<R> rs;
  for (ll i = ll(0); i < ll(m); i++) {
    ll x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--;
    y1--;
    xs.push_back(x1);
    xs.push_back(x2);
    ys.push_back(y1);
    ys.push_back(y2);
    rs.emplace_back(x1, x2, y1, y2);
  }
  mkuni(xs);
  mkuni(ys);
  ll first = xs.size() - 1, second = ys.size() - 1;
  maxflow<ll> mf(1 + first + second + 1);
  for (ll i = ll(0); i < ll(first); i++) {
    mf.ae(0, 1 + i, xs[i + 1] - xs[i]);
  }
  for (ll i = ll(0); i < ll(second); i++) {
    mf.ae(1 + first + i, 1 + first + second, ys[i + 1] - ys[i]);
  }
  vvc<ll> w(first, vi(second));
  for (auto r : rs) {
    ll x1, x2, y1, y2;
    tie(x1, x2, y1, y2) = r;
    x1 = lower_bound(xs.begin(), xs.end(), x1) - xs.begin();
    x2 = lower_bound(xs.begin(), xs.end(), x2) - xs.begin();
    y1 = lower_bound(ys.begin(), ys.end(), y1) - ys.begin();
    y2 = lower_bound(ys.begin(), ys.end(), y2) - ys.begin();
    for (ll i = ll(x1); i < ll(x2); i++)
      for (ll j = ll(y1); j < ll(y2); j++) w[i][j] = 1;
  }
  for (ll i = ll(0); i < ll(first); i++)
    for (ll j = ll(0); j < ll(second); j++)
      if (w[i][j]) mf.ae(1 + i, 1 + first + j, inf);
  void(0);
  cout << mf.calc(0, 1 + first + second) << endl;
}