#include <bits/stdc++.h>
using namespace std;
int n, m, k, a[1010], b[1010], tg[1010][1010], s;
vector<int> x, y;
vector<int>::iterator it;
bool check(int lim) {
  x.clear(), y.clear();
  for (int i = 1; i <= k; i++) {
    int Up = max(1, a[i] - lim), Down = min(n, a[i] + lim);
    int Left = max(1, b[i] - lim), Right = min(m, b[i] + lim);
    x.push_back(Up), x.push_back(Down + 1);
    y.push_back(Left), y.push_back(Right + 1);
  }
  x.push_back(1), x.push_back(n + 1);
  y.push_back(1), y.push_back(m + 1);
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  x.erase(unique(x.begin(), x.end()), x.end());
  y.erase(unique(y.begin(), y.end()), y.end());
  memset(tg, 0, sizeof(tg));
  for (int i = 1; i <= k; i++) {
    int Up = max(1, a[i] - lim), Down = min(n, a[i] + lim);
    int Left = max(1, b[i] - lim), Right = min(m, b[i] + lim);
    Up = lower_bound(x.begin(), x.end(), Up) - x.begin() + 1;
    Down = lower_bound(x.begin(), x.end(), Down + 1) - x.begin() + 1;
    Left = lower_bound(y.begin(), y.end(), Left) - y.begin() + 1;
    Right = lower_bound(y.begin(), y.end(), Right + 1) - y.begin() + 1;
    tg[Up][Left]++, tg[Up][Right]--;
    tg[Down][Left]--, tg[Down][Right]++;
  }
  int minx = 1000000000, miny = 1000000000, maxx = 0, maxy = 0;
  for (int i = 1; i < (int)x.size(); i++)
    for (int j = 1; j < (int)y.size(); j++) {
      tg[i][j] += tg[i][j - 1] + tg[i - 1][j] - tg[i - 1][j - 1];
      if (!tg[i][j]) {
        minx = min(minx, i), maxx = max(maxx, i);
        miny = min(miny, j), maxy = max(maxy, j);
      }
    }
  if (minx == 1000000000) return 1;
  minx = x[minx - 1], miny = y[miny - 1];
  maxx = x[maxx] - 1, maxy = y[maxy] - 1;
  return (maxx - minx <= lim * 2 && maxy - miny <= lim * 2);
}
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= k; i++) cin >> a[i] >> b[i];
  int l = 0, r = max(n, m) / 2, ret = 0;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid))
      ret = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d\n", ret);
  return 0;
}
