#include <bits/stdc++.h>
int xabs[1000100];
int nx[2020];
std::vector<std::pair<int, std::pair<int, int>>> evt;
std::set<std::pair<int, int>, std::greater<std::pair<int, int>>> bst;
std::vector<std::pair<int, int>> rb;
std::vector<std::pair<int, int>> st;
std::vector<int> pi;
int main(void) {
  int n, m;
  scanf("%d %d", &n, &m);
  int x, y;
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &x, &y);
    rb.push_back({x, y});
  };
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &x, &y);
    st.push_back({x, y});
  };
  std::sort(st.begin(), st.end(), std::greater<std::pair<int, int>>());
  y = -1;
  for (auto nxt : st) {
    if (nxt.second > y) {
      pi.push_back(nxt.second + 1);
      for (int i = y + 1; i <= nxt.second; i++) {
        xabs[i] = nxt.first;
      };
      y = nxt.second;
    };
  };
  for (auto nxt : pi) {
    for (int i = 0; i < rb.size(); i++) {
      auto r = rb[i];
      if (r.second < nxt) {
        evt.push_back({nxt - r.second, {i, (xabs[nxt] - r.first) + 1}});
      };
    };
  };
  std::sort(evt.begin(), evt.end(),
            std::less<std::pair<int, std::pair<int, int>>>());
  int erg = 0;
  for (int i = 0; i < rb.size(); i++) {
    auto r = rb[i];
    nx[i] = std::max((xabs[r.second] - r.first) + 1, 0);
    bst.insert({nx[i], i});
  };
  erg = std::max(bst.begin()->first, 0);
  for (auto nxt : evt) {
    int tmp = std::max(nxt.first, 0);
    bst.erase({nx[nxt.second.first], nxt.second.first});
    nx[nxt.second.first] = nxt.second.second;
    bst.insert({nx[nxt.second.first], nxt.second.first});
    tmp += std::max(bst.begin()->first, 0);
    erg = std::min(erg, tmp);
  };
  printf("%d\n", erg);
  return 0;
};
