#include <bits/stdc++.h>
using namespace std;
const int MAXN = 505;
int dp[MAXN << 1][MAXN << 1];
int W, H, K;
int px[MAXN], py[MAXN];
bool ok(int d) {
  vector<int> X, Y;
  X.push_back(0), X.push_back(W);
  Y.push_back(0), Y.push_back(H);
  for (int k = 0; k < K; ++k) {
    X.push_back(max(0, px[k] - d)), X.push_back(min(W, px[k] + d + 1));
    Y.push_back(max(0, py[k] - d)), Y.push_back(min(H, py[k] + d + 1));
  }
  sort((X).begin(), (X).end());
  X.erase(unique((X).begin(), (X).end()), X.end());
  sort((Y).begin(), (Y).end());
  Y.erase(unique((Y).begin(), (Y).end()), Y.end());
  memset(dp, 0, sizeof(dp));
  for (int k = 0; k < K; ++k) {
    int xs = lower_bound((X).begin(), (X).end(), max(0, px[k] - d)) - X.begin();
    int xe =
        lower_bound((X).begin(), (X).end(), min(W, px[k] + d + 1)) - X.begin();
    int ys = lower_bound((Y).begin(), (Y).end(), max(0, py[k] - d)) - Y.begin();
    int ye =
        lower_bound((Y).begin(), (Y).end(), min(H, py[k] + d + 1)) - Y.begin();
    assert(xs < xe && ys < ye);
    ++dp[xs][ys], ++dp[xe][ye];
    --dp[xs][ye], --dp[xe][ys];
  }
  int L = W, R = -1;
  int U = H, D = -1;
  for (int i = 0; i < X.size() - 1; ++i)
    for (int j = 0; j < Y.size() - 1; ++j) {
      if (i && j)
        dp[i][j] += dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      else if (i)
        dp[i][j] += dp[i - 1][j];
      else if (j)
        dp[i][j] += dp[i][j - 1];
      if (dp[i][j]) continue;
      L = min(L, X[i]), R = max(R, X[i + 1] - 1);
      U = min(U, Y[j]), D = max(D, Y[j + 1] - 1);
    }
  return max(R - L, D - U) <= 2 * d;
}
int main(void) {
  scanf("%d%d%d", &W, &H, &K);
  for (int i = 0; i < K; ++i) {
    scanf("%d%d", px + i, py + i);
    --px[i], --py[i];
  }
  int L = -1, R = max(W, H);
  while (R - L > 1) {
    int M = (L + R) >> 1;
    if (ok(M))
      R = M;
    else
      L = M;
  }
  printf("%d\n", R);
  return 0;
}
