#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long maxn = 3e3 + 100;
const long long inf = 1e9;
const long long maxc = 1e6 + 100;
long long n, m, k, t;
long long X[maxn];
long long Y[maxn];
long long X1[maxn];
long long Y1[maxn];
long long MX[maxc];
long long ANS[maxc];
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long q, w, e, a, b, c;
  cin >> n >> m;
  for (q = 0; q < n; q++) {
    cin >> X[q] >> Y[q];
  }
  for (q = 0; q < maxc; q++) {
    MX[q] = -maxc;
  }
  for (q = 0; q < m; q++) {
    cin >> X1[q] >> Y1[q];
    MX[X1[q]] = max(MX[X1[q]], Y1[q]);
  }
  vector<long long> I;
  for (q = maxc - 2; q >= 0; q--) {
    MX[q] = max(MX[q], MX[q + 1]);
    if (MX[q] != MX[q + 1]) {
      I.push_back(q);
    }
  }
  for (q = 0; q < n; q++) {
    for (auto i : I) {
      if (i < X[q]) {
        continue;
      }
      long long dx = i - X[q], dy = max(MX[i] - Y[q] + 1, 0LL);
      ANS[dx] = max(ANS[dx], dy);
    }
  }
  long long ans = maxc * maxc;
  long long mx = 0;
  for (q = maxc - 1; q >= 0; q--) {
    mx = max(mx, ANS[q]);
    long long dans = q + mx;
    ans = min(ans, dans);
  }
  cout << ans;
  return 0;
}
