#include <bits/stdc++.h>
using namespace std;
const int M = 105;
const int Inf = 2e9;
int n;
int L[M], R[M], U[M], D[M];
struct sdnode {
  int id, v, ty;
  bool operator<(const sdnode &b) const { return v < b.v; }
} B[M];
int btot, ctot, rtot;
int Shadc[M], Shadr[M];
void Shadmay() {
  for (int i = 1; i <= n; i++) B[++btot] = (sdnode){i, L[i], 0};
  for (int i = 1; i <= n; i++) B[++btot] = (sdnode){i, R[i] + 1, 1};
  sort(B + 1, B + btot + 1);
  for (int i = 1; i <= btot; i++) {
    if (i == 1 or B[i].v != B[i - 1].v) Shadc[++ctot] = B[i].v;
    if (B[i].ty == 0) L[B[i].id] = ctot;
    if (B[i].ty == 1) R[B[i].id] = ctot;
  }
  btot = 0;
  for (int i = 1; i <= n; i++) B[++btot] = (sdnode){i, U[i], 0};
  for (int i = 1; i <= n; i++) B[++btot] = (sdnode){i, D[i] + 1, 1};
  sort(B + 1, B + btot + 1);
  for (int i = 1; i <= btot; i++) {
    if (i == 1 or B[i].v != B[i - 1].v) Shadr[++rtot] = B[i].v;
    if (B[i].ty == 0) U[B[i].id] = rtot;
    if (B[i].ty == 1) D[B[i].id] = rtot;
  }
  ctot--;
  rtot--;
}
namespace NetworkFlow {
const int MM = 505;
struct Edge {
  int v, to, flow;
} E[50005];
int Head[MM], e_tot = 1;
void Link(int u, int v, int flow) {
  E[++e_tot] = (Edge){v, Head[u], flow}, Head[u] = e_tot;
}
void Linke(int u, int v, int flow) {
  Link(v, u, 0);
  Link(u, v, flow);
}
int tot, s, t;
int dep[MM], cur[MM];
bool vis[MM];
int Q[MM], l, r;
bool bfs() {
  for (int i = 1; i <= tot; i++) vis[i] = false, cur[i] = Head[i];
  l = r = 0;
  Q[r++] = s;
  vis[s] = true;
  while (l < r) {
    int u = Q[l++];
    for (int i = Head[u]; i; i = E[i].to) {
      int v = E[i].v;
      if (vis[v] or !E[i].flow) continue;
      vis[v] = true;
      dep[v] = dep[u] + 1;
      Q[r++] = v;
      if (v == t) return true;
    }
  }
  return false;
}
int dfs(int u, int rest) {
  if (u == t or !rest) return rest;
  int don, sm = 0;
  for (int &i = cur[u]; i; i = E[i].to) {
    int v = E[i].v;
    if (dep[v] != dep[u] + 1 or !E[i].flow) continue;
    sm += (don = dfs(v, min(rest, E[i].flow)));
    E[i].flow -= don;
    E[i ^ 1].flow += don;
    if (!(rest -= don)) break;
  }
  return sm;
}
int Dinic() {
  int Maxflow = 0;
  while (bfs()) Maxflow += dfs(s, Inf);
  return Maxflow;
}
};  // namespace NetworkFlow
using namespace NetworkFlow;
bool Mk[M][M];
int Er[M], Ec[M];
void Solve() {
  Shadmay();
  for (int i = 1; i <= n; i++)
    for (int j = U[i]; j < D[i]; j++)
      for (int q = L[i]; q < R[i]; q++) Mk[j][q] = true;
  tot = rtot + ctot + 2;
  s = tot - 1;
  t = tot;
  for (int i = 1; i <= rtot; i++)
    Linke(s, i, Shadr[i + 1] - Shadr[i]), Er[i] = e_tot;
  for (int i = 1; i <= ctot; i++)
    Linke(i + rtot, t, Shadc[i + 1] - Shadc[i]), Ec[i] = e_tot;
  for (int i = 1; i <= rtot; i++)
    for (int j = 1; j <= ctot; j++)
      if (Mk[i][j]) Linke(i, j + rtot, Inf);
  int dinic = Dinic();
  printf("%d\n", dinic);
}
int main() {
  scanf("%*d%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d%d%d%d", &U[i], &L[i], &D[i], &R[i]);
  Solve();
  return 0;
}
