#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
const int MAX_MEM = 2e8;
int mpos = 0;
char mem[MAX_MEM];
inline void *operator new(size_t n) {
  char *res = mem + mpos;
  mpos += n;
  assert(mpos <= MAX_MEM);
  return (void *)res;
}
inline void operator delete(void *) {}
int i, j, k, l, n, m, mn = ((int)1e9 + 9ll);
pair<int, int> a[1000009], b[1000009];
int suff[1000009], pos[1000009];
vector<int> nums;
inline bool cmp(pair<int, int> a, pair<int, int> b) {
  if (a.first != b.first) return a.first < b.first;
  return a.second < b.second;
}
vector<int> vs[1000009];
priority_queue<pair<int, int> > q;
int res[1000009];
vector<pair<int, int> > dp[1000009];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
  for (i = 1; i <= m; i++) cin >> b[i].first >> b[i].second;
  sort(b + 1, b + 1 + m, cmp);
  sort(a + 1, a + 1 + n, cmp);
  for (i = m; i > 0; i--) {
    suff[i] = max(suff[i + 1], b[i].second);
  }
  suff[m + 1] = -((int)1e9 + 9ll);
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      if (b[j].first >= a[i].first) {
        pos[i] = j;
        q.push({suff[j] - a[i].second + 1, i});
        res[i] = suff[j] - a[i].second + 1;
        break;
      }
    }
    if (pos[i] == 0) {
      pos[i] = m + 1;
      q.push({-((int)1e9 + 9ll) - a[i].second + 1, i});
      res[i] = -((int)1e9 + 9ll) - a[i].second + 1;
    }
  }
  long long kilk = 0;
  for (i = 1; i <= n; i++) {
    for (j = pos[i]; j <= m; j++) {
      if (b[j].first == b[j - 1].first) continue;
      dp[b[j].first - a[i].first + 1].push_back(
          {suff[j + 1] - a[i].second + 1, i});
    }
  }
  int ans = max(0, q.top().first);
  for (i = 1; i <= 1000001; i++) {
    for (auto to : dp[i]) {
      res[to.second] = to.first;
      q.push({res[to.second], to.second});
    }
    while (!q.empty() && q.top().first != res[q.top().second]) q.pop();
    ans = min(ans, i + max(0, q.top().first));
  }
  cout << ans << '\n';
  exit(0);
}
