#include <bits/stdc++.h>
using namespace std;
struct Point {
  int x, y;
} p[2010], q[2010];
bool cmp(Point a, Point b) { return a.x < b.x || (a.x == b.x && a.y > b.y); }
struct Val {
  Point a;
  int id;
} v[4000010];
bool cmp1(Val a, Val b) { return cmp(a.a, b.a); }
const int INF = 1000001;
int mx[2010];
int cnt[2000010];
int curans;
void add(int a, int b) {
  cnt[a] += b;
  return;
}
int getmx() {
  while (!cnt[curans]) curans--;
  return curans;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d%d", &p[i].x, &p[i].y);
  for (int i = 1; i <= m; i++) scanf("%d%d", &q[i].x, &q[i].y);
  sort(q + 1, q + m + 1, cmp);
  int N = 0;
  for (int i = 1; i <= m; i++) {
    while (N && q[N].y < q[i].y) N--;
    q[++N] = q[i];
  }
  m = N;
  N = 0;
  curans = INF;
  for (int i = 1; i <= n; i++) {
    add(INF, 1);
    mx[i] = INF;
    v[++N].id = i;
    v[N].a.x = 0;
    v[N].a.y = max(0, q[1].y - p[i].y + 1);
    for (int j = 1; j < m; j++) {
      v[++N].id = i;
      v[N].a.x = max(0, q[j].x - p[i].x + 1);
      v[N].a.y = max(0, q[j + 1].y - p[i].y + 1);
    }
    v[++N].id = i;
    v[N].a.x = max(0, q[m].x - p[i].x + 1);
    v[N].a.y = 0;
  }
  sort(v + 1, v + N + 1, cmp1);
  int ans = INF;
  for (int i = 1; i <= N; i++) {
    add(mx[v[i].id], -1);
    mx[v[i].id] = v[i].a.y;
    add(mx[v[i].id], 1);
    ans = min(ans, v[i].a.x + getmx());
  }
  printf("%d\n", ans);
  return 0;
}
