#include <bits/stdc++.h>
using namespace std;
struct light {
  int x, y;
  bool operator<(const light &other) const { return y > other.y; }
};
const int MAXN = 2010;
const int LIM = 1000010;
light lights[MAXN];
vector<int> advances[LIM];
int rightmost[LIM];
int sol[MAXN];
multiset<int> sols;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> robbers(n);
  set<int> important;
  for (int i = 0; i < n; i++) cin >> robbers[i].first >> robbers[i].second;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    important.insert(y);
    rightmost[y] = max(rightmost[y], x);
  }
  for (int i = 1000000; i >= 0; i--)
    rightmost[i] = max(rightmost[i], rightmost[i + 1]);
  for (auto &y : important) {
    for (int i = 0; i < n; i++) {
      if (y >= robbers[i].second)
        advances[y + 1 - robbers[i].second].push_back(i);
    }
  }
  for (int i = 0; i < n; i++) {
    sol[i] = max(0, rightmost[robbers[i].second] + 1 - robbers[i].first);
    sols.insert(sol[i]);
  }
  int ans = 2 * LIM;
  for (int goes_up = 0; goes_up <= LIM - 10; goes_up++) {
    for (auto &x : advances[goes_up]) {
      int new_y = robbers[x].second + goes_up;
      sols.erase(sols.find(sol[x]));
      sol[x] = max(0, rightmost[new_y] + 1 - robbers[x].first);
      sols.insert(sol[x]);
    }
    ans = min(ans, goes_up + *sols.rbegin());
  }
  cout << ans << endl;
  return 0;
}
