#include <bits/stdc++.h>
using namespace std;
const int N = 100;
tuple<int, int, int, int> r[N];
int vx[N], vy[N];
set<int> ix, iy, sx, sy;
set<int> e[N];
int fl[N][N];
bool seen[2 * N];
int dfs(int v, int f) {
  if (seen[v]) return 0;
  seen[v] = 1;
  if (v < N) {
    int x = v;
    for (int y : e[x]) {
      int fo = dfs(y + N, f);
      if (fo) {
        fl[x][y] += fo;
        return fo;
      }
    }
  } else {
    int y = v - N;
    if (vy[y]) {
      int fo = min(f, vy[y]);
      vy[y] -= fo;
      return fo;
    }
    for (int x = 0; x < N; x++)
      if (fl[x][y]) {
        int fo = min(f, fl[x][y]);
        fo = dfs(x, fo);
        if (fo) {
          fl[x][y] -= fo;
          return fo;
        }
      }
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  if (!m) {
    cout << "0\n";
    return 0;
  }
  for (int i = 0; i < m; i++) {
    int lx, hx, ly, hy;
    cin >> lx >> ly >> hx >> hy;
    r[i] = {lx, ++hx, ly, ++hy};
    ix.insert(lx);
    ix.insert(hx);
    iy.insert(ly);
    iy.insert(hy);
  }
  map<int, int> mx, my;
  {
    int i = 0;
    auto it1 = ix.begin();
    auto it2 = it1;
    it2++;
    while (it2 != ix.end()) {
      int d = *it2 - *it1;
      mx[*it1] = i;
      vx[i] = d;
      it1++;
      it2++;
      i++;
    }
    mx[*it1] = i;
    i = 0;
    it1 = iy.begin();
    it2 = it1;
    it2++;
    while (it2 != iy.end()) {
      int d = *it2 - *it1;
      my[*it1] = i;
      vy[i] = d;
      it1++;
      it2++;
      i++;
    }
    my[*it1] = i;
  }
  for (int i = 0; i < m; i++) {
    int lx, hx, ly, hy;
    tie(lx, hx, ly, hy) = r[i];
    lx = mx[lx];
    hx = mx[hx];
    ly = my[ly];
    hy = my[hy];
    for (int x = lx; x < hx; x++)
      for (int y = ly; y < hy; y++) e[x].insert(y);
  }
  int mf = 0;
  int lx = 0;
  for (int x = 0; x < N; x++)
    for (int f = 1; f && vx[x];) {
      fill(seen, seen + 2 * N, 0);
      f = dfs(x, vx[x]);
      vx[x] -= f;
      mf += f;
    }
  cout << mf << '\n';
}
