#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
void dbg_out() { cout << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cout << ' ' << H;
  dbg_out(T...);
}
const long long int INF = 1e9 + 3;
const long long int N = 1e6 + 1;
const long long int MOD = 1e9 + 7;
void solve() {
  long long int n, m;
  cin >> n >> m;
  vector<pair<long long int, long long int> > r(n), l(m);
  for (long long int i = (0); i < (n); i++) cin >> r[i].first >> r[i].second;
  for (long long int i = (0); i < (m); i++) cin >> l[i].first >> l[i].second;
  vector<pair<long long int, long long int> > fl;
  for (long long int i = (0); i < (n); i++) {
    for (long long int j = (0); j < (m); j++) {
      if (r[i].first <= l[j].first && r[i].second <= l[j].second) {
        fl.emplace_back(l[j].first - r[i].first, l[j].second - r[i].second);
      }
    }
  }
  sort((fl).begin(), (fl).end());
  for (long long int i = (long long int)fl.size() - 2; i >= 0; i--) {
    if (fl[i].second < fl[i + 1].second) {
      fl[i].second = fl[i + 1].second;
    }
  }
  long long int ans = INF;
  for (long long int i = (0); i < ((long long int)fl.size()); i++) {
    if (i == 0) ans = min(ans, fl[i].second + 1);
    if (i == (long long int)fl.size() - 1) ans = min(ans, fl[i].first + 1);
    if (i != 0) ans = min(ans, fl[i - 1].first + fl[i].second + 2);
  }
  cout << (ans == INF ? 0 : ans) << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int T = 1;
  for (long long int test = (1); test < (T + 1); test++) {
    solve();
  }
  return 0;
}
