#include <bits/stdc++.h>
using namespace std;
int x[1000], y[1000], k, n, m;
bool chck(int xx) {
  vector<int> v;
  v.push_back(1);
  v.push_back(m);
  for (int i = 0; i < k; ++i) {
    v.push_back(max(1, x[i] - xx));
    v.push_back(max(1, x[i] - xx - 1));
    v.push_back(min(m, x[i] + xx));
    v.push_back(min(m, x[i] + xx + 1));
  }
  sort(v.begin(), v.end());
  int mn = 1e9, mx = -1, tmp, nm, c;
  bool l;
  vector<pair<int, int> > f;
  for (int i = 0; i < v.size(); ++i) {
    tmp = v[i];
    f.clear();
    for (int j = 0; j < k; ++j) {
      if (x[j] - xx <= tmp && x[j] + xx >= tmp) {
        f.push_back(make_pair(max(1, y[j] - xx), 0));
        f.push_back(make_pair(min(n, y[j] + xx), 1));
      }
    }
    sort(f.begin(), f.end());
    c = 0;
    nm = 0;
    l = 0;
    for (int j = 0; j < f.size(); ++j) {
      if (nm == 0) {
        if (f[j].first != c + 1) {
          break;
        }
      }
      c = f[j].first;
      if (f[j].second == 0)
        ++nm;
      else
        --nm;
      if (c == n) {
        l = 1;
        break;
      }
    }
    if (!l) {
      mn = min(mn, tmp);
      mx = max(mx, tmp);
    }
  }
  mx = min(mx, m);
  mn = max(1, mn);
  if (mx - mn + 1 > xx + xx + 1) {
    return 0;
  }
  v.clear();
  v.push_back(1);
  v.push_back(n);
  for (int i = 0; i < k; ++i) {
    v.push_back(max(1, y[i] - xx));
    v.push_back(max(1, y[i] - xx - 1));
    v.push_back(min(n, y[i] + xx));
    v.push_back(min(n, y[i] + xx + 1));
  }
  sort(v.begin(), v.end());
  mn = 1e9, mx = -1;
  for (int i = 0; i < v.size(); ++i) {
    tmp = v[i];
    f.clear();
    for (int j = 0; j < k; ++j) {
      if (y[j] - xx <= tmp && y[j] + xx >= tmp) {
        f.push_back(make_pair(max(1, x[j] - xx), 0));
        f.push_back(make_pair(min(m, x[j] + xx), 1));
      }
    }
    sort(f.begin(), f.end());
    c = 0;
    nm = 0;
    l = 0;
    for (int j = 0; j < f.size(); ++j) {
      if (nm == 0) {
        if (f[j].first != c + 1) {
          break;
        }
      }
      c = f[j].first;
      if (f[j].second == 0)
        ++nm;
      else
        --nm;
      if (c == m) {
        l = 1;
        break;
      }
    }
    if (!l) {
      mn = min(mn, tmp);
      mx = max(mx, tmp);
    }
  }
  mx = min(mx, n);
  mn = max(1, mn);
  if (mx - mn + 1 > xx + xx + 1) {
    return 0;
  }
  return 1;
}
int main() {
  while (cin >> m >> n >> k) {
    for (int i = 0; i < k; ++i) {
      scanf("%d%d", &x[i], &y[i]);
    }
    int st = 0, nd = 1e9, md;
    while (st < nd) {
      md = (st + nd) / 2;
      if (chck(md)) {
        nd = md;
      } else {
        st = md + 1;
      }
    }
    printf("%d\n", nd);
  }
  return 0;
}
