#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 1;
int n, m, c[N];
pair<int, int> a[N], b[N];
vector<pair<int, int> > v1, v2;
void process(vector<pair<int, int> > &x) {
  vector<pair<int, int> > y;
  sort(x.begin(), x.end());
  for (int i = 0; i < x.size(); i++) {
    while (!y.empty() && y.back().first <= x[i].first &&
           y.back().second <= x[i].second)
      y.pop_back();
    y.push_back(x[i]);
  }
  x = y;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie();
  int test = 1;
  while (test--) {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
      cin >> a[i].first >> a[i].second;
      v1.push_back(a[i]);
    }
    for (int i = 1; i <= m; i++) {
      cin >> b[i].first >> b[i].second;
      v2.push_back(b[i]);
    }
    process(v1);
    process(v2);
    int it = 0, ans = 0, tmp = 0;
    vector<pair<int, pair<int, int> > > v;
    priority_queue<pair<int, int>, vector<pair<int, int> >,
                   less<pair<int, int> > >
        pq;
    for (int i = 0; i < v1.size(); i++) {
      while (it < v2.size() && v2[it].first < v1[i].first) it++;
      if (it < v2.size()) {
        c[i] = max(0, v2[it].second + 1 - v1[i].second);
        pq.push({c[i], i});
        tmp = max(tmp, c[i]);
        for (int j = it; j < v2.size(); j++) {
          v.push_back({v2[j].first + 1 - v1[i].first, {j + 1, i}});
        }
      }
    }
    ans = tmp;
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); i++) {
      int id = v[i].second.second, li = v[i].second.first;
      c[id] = (li < v2.size()) ? max(v2[li].second + 1 - v1[id].second, 0) : 0;
      while (!pq.empty() && c[pq.top().second] != pq.top().first) pq.pop();
      pq.push({c[id], id});
      if (i + 1 == v.size() ||
          (i + 1 < v.size() && v[i + 1].first != v[i].first)) {
        ans = min(ans, v[i].first + pq.top().first);
      }
    }
    cout << ans << endl;
  }
}
