#include <bits/stdc++.h>
using namespace std;
const int M = 205, inf = 1e9;
int n, m;
int lx[M >> 2], rx[M >> 2], ly[M >> 2], ry[M >> 2];
int tx[M >> 1], ty[M >> 1], cx, cy;
bool mark[M >> 1][M >> 1];
int h[M], nx[M * M >> 1], to[M * M >> 1], v[M * M >> 1], tot = 1;
void add(int a, int b, int c) {
  to[++tot] = b;
  v[tot] = c;
  nx[tot] = h[a];
  h[a] = tot;
}
void adds(int a, int b, int c) {
  add(a, b, c);
  add(b, a, 0);
}
int dep[M], q[M];
bool bfs() {
  memset(dep, 0, sizeof(dep));
  int l = 0, r = 0;
  dep[q[r++] = 0] = 1;
  while (l < r) {
    int x = q[l++];
    for (int i = h[x]; i; i = nx[i]) {
      int y = to[i];
      if (v[i] && !dep[y]) {
        dep[y] = dep[x] + 1;
        if (y == cx + cy + 1) return true;
        q[r++] = y;
      }
    }
  }
  return false;
}
int cur[M];
int dfs(int x, int fl) {
  if (x == cx + cy + 1) return fl;
  int res = 0;
  for (int &i = cur[x]; i; i = nx[i]) {
    int y = to[i], inc;
    if (v[i] && dep[y] == dep[x] + 1 && (inc = dfs(y, min(fl, v[i])))) {
      v[i] -= inc, v[i ^ 1] += inc;
      fl -= inc, res += inc;
      if (!fl) break;
    }
  }
  return res;
}
int dinic() {
  int ans = 0;
  while (bfs()) {
    memcpy(cur, h, sizeof(cur));
    ans += dfs(0, inf);
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d%d", &lx[i], &ly[i], &rx[i], &ry[i]);
    rx[i]++, ry[i]++;
    tx[++cx] = lx[i], tx[++cx] = rx[i];
    ty[++cy] = ly[i], ty[++cy] = ry[i];
  }
  sort(tx + 1, tx + 1 + cx);
  sort(ty + 1, ty + 1 + cy);
  cx = unique(tx + 1, tx + 1 + cx) - tx - 1;
  cy = unique(ty + 1, ty + 1 + cy) - ty - 1;
  for (int i = 1; i < cx; i++) adds(0, i, tx[i + 1] - tx[i]);
  for (int i = 1; i < cy; i++) adds(cx + i, cx + cy + 1, ty[i + 1] - ty[i]);
  for (int t = 1; t <= m; t++) {
    lx[t] = lower_bound(tx + 1, tx + 1 + cx, lx[t]) - tx;
    rx[t] = lower_bound(tx + 1, tx + 1 + cx, rx[t]) - tx;
    ly[t] = lower_bound(ty + 1, ty + 1 + cy, ly[t]) - ty;
    ry[t] = lower_bound(ty + 1, ty + 1 + cy, ry[t]) - ty;
    for (int i = lx[t]; i < rx[t]; i++)
      for (int j = ly[t]; j < ry[t]; j++)
        if (!mark[i][j]) mark[i][j] = 1, adds(i, cx + j, inf);
  }
  printf("%d\n", dinic());
  return 0;
}
