#include <bits/stdc++.h>
using namespace std;
const long long N = 1005;
pair<long long, long long> q1[4100005];
pair<long long, long long> q2[4100005];
long long a1[4100005];
signed main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> q1[i].first >> q1[i].second;
  for (long long i = 1; i <= m; i++) cin >> q2[i].first >> q2[i].second;
  vector<pair<long long, long long> > v;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (q2[j].first < q1[i].first || q2[j].second < q1[i].second) continue;
      v.push_back({max(q2[j].first - q1[i].first + 1, 0ll),
                   max(0ll, q2[j].second - q1[i].second + 1)});
    }
  }
  if (v.empty()) {
    cout << 0;
    return 0;
  }
  sort(v.begin(), v.end());
  for (long long i = v.size() - 1; i >= 0; i--)
    a1[i] = max(a1[i + 1], v[i].second);
  long long ans = a1[0];
  for (long long i = 0; i < v.size(); ++i)
    ans = min(ans, v[i].first + a1[i + 1]);
  cout << ans;
}
