#include <bits/stdc++.h>
using namespace std;
int n, m, k;
pair<int, int> A[200006];
struct poi {
  int x, l, r, d;
} W[200006];
int cnt = 0;
int tr[200006];
bool chk(int d) {
  cnt = 0;
  vector<int> dy;
  for (int i = (1), iend = (k); i <= iend; ++i) {
    int x = A[i].first, y = A[i].second;
    dy.push_back(max(y - d, 1)), dy.push_back(min(y + d, m));
    dy.push_back(max(y - d - 1, 1)), dy.push_back(min(y + d + 1, m));
    W[++cnt] = (poi){max(x - d, 1), max(y - d, 1), min(y + d, m), 1};
    W[++cnt] = (poi){min(x + d + 1, n + 1), max(y - d, 1), min(y + d, m), -1};
  }
  sort(W + 1, W + 1 + cnt,
       [](poi& a, poi& b) { return a.x == b.x ? a.d < b.d : a.x < b.x; });
  sort((dy).begin(), (dy).end());
  dy.erase(unique((dy).begin(), (dy).end()), dy.end());
  auto getit = [&](int y) {
    return lower_bound((dy).begin(), (dy).end(), y) - dy.begin() + 1;
  };
  int sz = dy.size();
  int lx = 0x3f3f3f3f, rx = -1, ly = 0x3f3f3f3f, ry = -1;
  if (W[1].x != 1) lx = 1, rx = 1, ly = 1, ry = sz;
  for (int i = (1), iend = (cnt); i <= iend; ++i) {
    if (W[i].x != 1 && (i == 1 || W[i].x != W[i - 1].x)) {
      int L = sz + 1, R = 0;
      for (int j = (1), jend = (sz); j <= jend; ++j)
        if (!tr[j]) {
          L = j;
          break;
        }
      for (int j = (sz), jend = (1); j >= jend; --j)
        if (!tr[j]) {
          R = j;
          break;
        }
      if (L != sz + 1)
        lx = min(lx, W[i].x - 1), rx = max(rx, W[i].x - 1), ly = min(ly, L),
        ry = max(ry, R);
    }
    int L = getit(W[i].l), R = getit(W[i].r);
    for (int j = (L), jend = (R); j <= jend; ++j) tr[j] += W[i].d;
    if (W[i].x != n + 1 && W[i].x != W[i + 1].x) {
      int L = sz + 1, R = 0;
      for (int j = (1), jend = (sz); j <= jend; ++j)
        if (!tr[j]) {
          L = j;
          break;
        }
      for (int j = (sz), jend = (1); j >= jend; --j)
        if (!tr[j]) {
          R = j;
          break;
        }
      if (L != sz + 1)
        lx = min(lx, W[i].x), rx = max(rx, W[i].x), ly = min(ly, L),
        ry = max(ry, R);
    }
  }
  if (W[cnt].x != n + 1) lx = min(lx, n), rx = max(rx, n), ly = 1, ry = sz;
  if (ly > 1e9) return true;
  ly = dy[ly - 1], ry = dy[ry - 1];
  if (ry - ly <= 2 * d && rx - lx <= 2 * d) return true;
  return false;
}
void solve() {
  cin >> n >> m >> k;
  for (int i = (1), iend = (k); i <= iend; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    A[i] = make_pair(x, y);
  }
  int l = 0, r = 1e9;
  while (l <= r) {
    int mid = l + r >> 1;
    if (chk(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  cout << l << endl;
}
signed main() { solve(); }
