#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int oo = 1000000001;
const int N = 500011;
int n, m, k;
int px(int x) { return min(n, max(x, 1)); }
int py(int y) { return min(m, max(y, 1)); }
int xx[510], yy[510], sum[2200][2200];
int idx(vector<int>& d, int val) {
  return lower_bound(d.begin(), d.end(), val) - d.begin() + 1;
}
bool check(int mid) {
  vector<int> dx, dy;
  dx.push_back(1);
  dx.push_back(n);
  dy.push_back(1);
  dy.push_back(m);
  for (int i = 0; i < k; i++) {
    dx.push_back(px(xx[i] + mid));
    dx.push_back(px(xx[i] - mid));
    dx.push_back(px(xx[i] + mid + 1));
    dx.push_back(px(xx[i] - mid - 1));
    dy.push_back(py(yy[i] + mid));
    dy.push_back(py(yy[i] - mid));
    dy.push_back(py(yy[i] + mid + 1));
    dy.push_back(py(yy[i] - mid - 1));
  }
  sort(dx.begin(), dx.end());
  dx.resize(unique(dx.begin(), dx.end()) - dx.begin());
  sort(dy.begin(), dy.end());
  dy.resize(unique(dy.begin(), dy.end()) - dy.begin());
  memset(sum, 0, sizeof sum);
  for (int i = 0; i < k; ++i) {
    int a = idx(dx, px(xx[i] - mid));
    int b = idx(dy, py(yy[i] - mid));
    int c = idx(dx, px(xx[i] + mid));
    int d = idx(dy, py(yy[i] + mid));
    sum[a][b]++;
    sum[c + 1][d + 1]++;
    sum[c + 1][b]--;
    sum[a][d + 1]--;
  }
  int mnX = oo, mxX = -1, mxY = -1, mnY = oo;
  for (int i = 1; i <= dx.size(); ++i) {
    for (int j = 1; j <= dy.size(); j++) {
      sum[i][j] = sum[i][j] + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
      if (!sum[i][j]) {
        mnX = min(mnX, dx[i - 1]);
        mxX = max(mxX, dx[i - 1]);
        mnY = min(mnY, dy[j - 1]);
        mxY = max(mxY, dy[j - 1]);
      }
    }
  }
  if (mxX == -1) return 1;
  return max(mxX - mnX + 1, mxY - mnY + 1) <= 2 * mid + 1;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < k; ++i) {
    scanf("%d%d", &xx[i], &yy[i]);
  }
  int lo = 0, hi = 1000000000;
  int best = -1;
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    if (check(mid)) {
      best = mid;
      hi = mid - 1;
    } else {
      lo = mid + 1;
    }
  }
  cout << best << endl;
  return 0;
}
