#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
const int maxa = 1e6 + 1;
int n, m, ans = 1000000000;
int x[maxn], y[maxn], a[maxn], b[maxn], ord[maxn];
int up[maxa + 5];
vector<int> ins[maxa + 5], era[maxa + 5];
multiset<int, greater<int> > s;
inline bool cmp(const int &i, const int &j) {
  return make_pair(a[i], b[i]) < make_pair(a[j], b[j]);
}
inline void upd(int l, int r, int k) {
  if (l > r) return;
  ins[l].push_back(k);
  era[r + 1].push_back(k);
  return;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (0); i < (n); ++i) scanf("%d%d", x + i, y + i);
  memset(up, -1, sizeof(up));
  for (int i = (0); i < (m); ++i) {
    scanf("%d%d", a + i, b + i);
    up[a[i]] = max(up[a[i]], b[i]);
    ord[i] = i;
  }
  for (int i = maxa; i >= 0; --i) up[i] = max(up[i], up[i + 1]);
  sort(ord, ord + m, cmp);
  for (int i = (0); i < (n); ++i) {
    for (int jt = m - 1; jt >= 0; --jt) {
      int j = ord[jt];
      int l = (jt ? a[ord[jt - 1]] + 1 : 0), r = a[j];
      if (r < x[i]) break;
      upd(max(l - x[i], 0), r - x[i], max(up[l] - y[i] + 1, 0));
    }
    if (x[i] <= a[ord[m - 1]]) upd(a[ord[m - 1]] - x[i] + 1, maxa, 0);
  }
  s.insert(0);
  for (int i = (0); i <= (maxa); ++i) {
    for (int j = (0); j < (ins[i].size()); ++j) s.insert(ins[i][j]);
    for (int j = (0); j < (era[i].size()); ++j) s.erase(s.find(era[i][j]));
    ans = min(ans, i + *s.begin());
  }
  printf("%d\n", ans);
  return 0;
}
