#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long a = 0, b = getchar(), c = 1;
  while (!isdigit(b)) c = b == '-' ? -1 : 1, b = getchar();
  while (isdigit(b)) a = a * 10 + b - '0', b = getchar();
  return a * c;
}
const int N = 2005;
long long n, m, ab, ac = 1e15, a[N], b[N], c[N], d[N], e[1000005];
int main() {
  n = read(), m = read();
  for (int i = 0; i < n; i++) a[i] = read(), b[i] = read();
  for (int i = 0; i < m; i++) c[i] = read(), d[i] = read();
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (c[j] >= a[i]) e[c[j] - a[i]] = max(e[c[j] - a[i]], d[j] - b[i] + 1);
  for (int i = 1000001; i >= 0; i--) {
    ab = max(ab, e[i]);
    ac = min(ac, i + ab);
  }
  cout << ac;
  return 0;
}
