#include <bits/stdc++.h>
using namespace std;
const long long N = 2005;
const long long M = 1e6 + 5;
const long long inf = 0x3f3f3f3f3f3f3f3f;
const long long mod = 1e9 + 7;
const long long mod2 = 998244353;
long long n, m;
vector<long long> v;
vector<long long> work;
vector<long long> work1;
vector<long long> uu;
long long num[N][N];
long long a[N], b[N], c[N], d[N];
long long L[N * N], U[N * N];
long long cnt;
struct Node {
  long long l;
  long long u;
} Q[N * N];
bool cmp(Node x, Node y) { return x.u > y.u; }
long long maxl, maxr;
map<long long, long long> Map;
signed main() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> a[i] >> b[i];
  for (long long i = 1; i <= m; i++) cin >> c[i] >> d[i];
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++)
      L[++cnt] = max(0LL, -a[i] + c[j] + 1),
      U[cnt] = max(0LL, -b[i] + d[j] + 1);
  for (long long i = 1; i <= cnt; i++) Q[i].l = L[i], Q[i].u = U[i];
  sort(Q + 1, Q + cnt + 1, cmp);
  for (long long i = 1; i <= cnt; i++)
    maxl = max(Q[i].l, maxl), maxr = max(Q[i].u, maxr);
  long long ans = inf;
  long long maxx = 0;
  for (long long i = 1; i <= cnt + 1; i++) {
    if (i != 1 && Q[i - 1].u > Q[i].u) ans = min(ans, Q[i].u + maxx);
    maxx = max(maxx, Q[i].l);
  }
  ans = min(ans, maxl);
  ans = min(ans, maxr);
  cout << ans << endl;
}
