#include <bits/stdc++.h>
using namespace std;
const int maxm = 200 + 10;
struct rect {
  int x1, y1, x2, y2;
  void readin() {
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    x2++;
    y2++;
  }
} a[maxm];
int n, m, src, dst;
vector<int> x, y;
bool b[maxm][maxm];
long long cap[maxm][maxm], ans;
int p[maxm], que[maxm];
bool find_path() {
  int head = 0, tail = 0;
  memset(p, -1, sizeof(p));
  que[tail++] = src;
  p[src] = src;
  while (head < tail) {
    int x = que[head++];
    for (int y = 0; y <= dst; y++) {
      if (cap[x][y] > 0 && p[y] == -1) {
        p[y] = x;
        que[tail++] = y;
      }
    }
  }
  return p[dst] != -1;
}
void push_flow() {
  long long flow = 1LL << 40;
  for (int v = dst; v != src; v = p[v]) {
    flow = min(flow, cap[p[v]][v]);
  }
  ans += flow;
  for (int v = dst; v != src; v = p[v]) {
    cap[p[v]][v] -= flow;
    cap[v][p[v]] += flow;
  }
}
void work() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    a[i].readin();
    x.push_back(a[i].x1);
    x.push_back(a[i].x2);
    y.push_back(a[i].y1);
    y.push_back(a[i].y2);
  }
  x.push_back(1);
  x.push_back(n + 1);
  y.push_back(1);
  y.push_back(n + 1);
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  x.erase(unique(x.begin(), x.end()), x.end());
  y.erase(unique(y.begin(), y.end()), y.end());
  for (int i = 0; i < m; i++) {
    int x1 = lower_bound(x.begin(), x.end(), a[i].x1) - x.begin();
    int x2 = lower_bound(x.begin(), x.end(), a[i].x2) - x.begin();
    int y1 = lower_bound(y.begin(), y.end(), a[i].y1) - y.begin();
    int y2 = lower_bound(y.begin(), y.end(), a[i].y2) - y.begin();
    for (int j = x1; j < x2; j++) {
      for (int k = y1; k < y2; k++) {
        b[j][k] = true;
      }
    }
  }
  src = x.size() + y.size() + 1;
  dst = src + 1;
  for (int i = 0; i < x.size() - 1; i++) {
    cap[src][i] = x[i + 1] - x[i];
  }
  for (int j = 0; j < y.size() - 1; j++) {
    cap[x.size() + j][dst] = y[j + 1] - y[j];
  }
  for (int i = 0; i < x.size(); i++) {
    for (int j = 0; j < y.size(); j++) {
      if (b[i][j]) {
        cap[i][x.size() + j] = 1LL << 40;
      }
    }
  }
  while (find_path()) {
    push_flow();
  }
  cout << ans << endl;
}
int main() {
  int TestCase = 1;
  while (TestCase--) {
    work();
  }
  return 0;
}
