#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1.0);
const double eps = 1e-9;
const long long mod = 1e9 + 7;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch<'0' | ch> '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void Out(int aa) {
  if (aa > 9) Out(aa / 10);
  putchar(aa % 10 + '0');
}
int x[505], y[505];
int dp[1010][1010];
int n, m, k;
bool check(int t) {
  vector<int> X, Y;
  X.push_back(1), X.push_back(n + 1);
  Y.push_back(1), Y.push_back(m + 1);
  for (int i = 1; i <= k; i++) {
    X.push_back(max(x[i] - t, 1)), X.push_back(min(n + 1, x[i] + t + 1));
    Y.push_back(max(1, y[i] - t)), Y.push_back(min(m + 1, y[i] + t + 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 i = 1; i <= k; i++) {
    int l1 = lower_bound(X.begin(), X.end(), max(x[i] - t, 1)) - X.begin();
    int l2 =
        lower_bound(X.begin(), X.end(), min(x[i] + t + 1, n + 1)) - X.begin();
    int r1 = lower_bound(Y.begin(), Y.end(), max(y[i] - t, 1)) - Y.begin();
    int r2 =
        lower_bound(Y.begin(), Y.end(), min(y[i] + t + 1, m + 1)) - Y.begin();
    dp[l1][r1]++, dp[l2][r2]++;
    dp[l1][r2]--;
    dp[l2][r1]--;
  }
  int l = n + 1, r = 0;
  int u = m + 1, d = 0;
  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 - 1] + dp[i][j - 1] + dp[i - 1][j];
      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 * t;
}
int main() {
  n = read(), m = read(), k = read();
  for (int i = 1; i <= k; i++) x[i] = read(), y[i] = read();
  int l = 0, r = max(n, m);
  int ans = r;
  while (r >= l) {
    int mid = (l + r) / 2;
    if (check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  Out(ans);
  return 0;
}
