#include <bits/stdc++.h>
using namespace std;
const int N = 2000 + 5;
const int LEN = 1e6 + 5;
int n, m;
int a[N], b[N], c[N], d[N], r[LEN];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
  for (int i = 1; i <= m; i++) cin >> c[i] >> d[i];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (a[i] <= c[j] && b[i] <= d[j])
        r[c[j] - a[i]] = max(r[c[j] - a[i]], d[j] - b[i] + 1);
  int res = LEN, tmp = 0;
  for (int i = LEN - 1; i >= 0; i--) {
    tmp = max(tmp, r[i]);
    res = min(res, i + tmp);
  }
  cout << res;
  return 0;
}
