#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int maxN = 2010;
const int N = 1e6 + 10;
pair<int, int> a[maxN];
int dp[N];
struct node {
  int x, add;
  node(int x = -1e9, int add = -1e9) : x(x), add(add) {}
};
node t[4 * N];
struct segmentTree {
  int getV(int v) { return max(t[v].add, t[v].x); }
  void push(int v) {
    t[2 * v + 1].add = max(t[2 * v + 1].add, t[v].add);
    t[2 * v + 2].add = max(t[2 * v + 2].add, t[v].add);
    t[v].add = -1e9;
  }
  void recalc(int v) { t[v].x = max(getV(2 * v + 1), getV(2 * v + 2)); }
  void add(int L, int R, int x, int v = 0, int tl = 0, int tr = N) {
    if (R <= tl || L >= tr || tr - tl < 1)
      return;
    else if (L <= tl && tr <= R)
      t[v].add = max(t[v].add, x);
    else {
      push(v);
      int mid = (tl + tr) / 2;
      add(L, R, x, 2 * v + 1, tl, mid);
      add(L, R, x, 2 * v + 2, mid, tr);
      recalc(v);
    }
  }
  int get(int ind, int v = 0, int tl = 0, int tr = N) {
    if (tr - tl == 1)
      return getV(v);
    else {
      push(v);
      int mid = (tl + tr) / 2;
      int ans = 0;
      if (ind >= mid)
        ans = get(ind, 2 * v + 2, mid, tr);
      else
        ans = get(ind, 2 * v + 1, tl, mid);
      recalc(v);
      return ans;
    }
  }
} tree;
int n, m;
int getCnt(int mid) {
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int ny = a[i].second + mid;
    int pans = -1e9;
    if (ny < N) pans = dp[ny];
    ans = max(ans, pans - a[i].first + 1);
  }
  return mid + ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    tree.add(0, b + 1, a);
  }
  for (int i = 0; i < N; ++i) dp[i] = tree.get(i);
  int ans = 1e9;
  for (int i = 0; i < 1e5; ++i) ans = min(ans, getCnt(i));
  for (int i = 1e6; i >= 1e6 - 1e5; --i) ans = min(ans, getCnt(i));
  cout << ans << "\n";
  return 0;
}
