#include <bits/stdc++.h>
using namespace std;
template <class C>
void mini(C& a, C b) {
  a = min(a, b);
}
template <class C>
void maxi(C& a, C b) {
  a = max(a, b);
}
void a() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n; i++) cin >> c[i];
  vector<int> p(n);
  p[0] = a[0];
  for (int(i) = 1; i <= n - 2; i++) {
    if (a[i] == p[i - 1])
      p[i] = b[i];
    else
      p[i] = a[i];
  }
  if (a.back() != p[0] and a.back() != p[n - 2])
    p[n - 1] = a.back();
  else if (b.back() != p[0] and b.back() != p[n - 2])
    p[n - 1] = b.back();
  else
    p[n - 1] = c.back();
  for (int i = 0; i < n; i++) cout << p[i] << ' ';
  cout << '\n';
}
void b() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  int diferentes = 1;
  for (int(i) = 1; i <= n - 1; i++)
    if (a[i] != a[i - 1]) diferentes++;
  if (k == 1 and diferentes != 1) {
    cout << "-1\n";
    return;
  }
  int res = 1;
  diferentes -= k;
  while (diferentes > 0) {
    res++;
    diferentes -= k - 1;
  }
  cout << res << '\n';
}
void c() {
  int n;
  long long l;
  cin >> n >> l;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  double izq = 0;
  double izqVel = 1;
  double der = l;
  double derVel = 1;
  int i = 0;
  int j = n - 1;
  double time = 0.0;
  while (i <= j) {
    double ti = (double)(a[i] - izq) / (double)izqVel;
    double tj = (double)(der - a[j]) / (double)derVel;
    if (ti < tj) {
      izq = a[i];
      i++;
      izqVel++;
      der -= ti * derVel;
      time += ti;
    } else {
      der = a[j];
      j--;
      derVel++;
      izq += tj * izqVel;
      time += tj;
    }
  }
  time += (der - izq) / (izqVel + derVel);
  cout << setprecision(9) << fixed << time << '\n';
}
void d() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n), c(m), d(m);
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
  for (int i = 0; i < m; i++) cin >> c[i] >> d[i];
  vector<pair<int, int> > delta;
  int dx, dy;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      dx = c[j] - a[i];
      dy = d[j] - b[i];
      if (dx >= 0 and dy >= 0) delta.push_back({dx, dy});
    }
  sort(delta.begin(), delta.end());
  if (delta.empty()) {
    cout << 0 << '\n';
    return;
  }
  int x = delta.back().first + 1;
  int maxy = -1;
  int res = x;
  for (int(i) = delta.size() - 1; i >= 1; i--) {
    x = delta[i - 1].first + 1;
    maxi(maxy, delta[i].second);
    mini(res, x + maxy + 1);
  }
  maxi(maxy, delta[0].second);
  mini(res, maxy + 1);
  cout << res << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  d();
  return 0;
}
