#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long POW(long long a, long long b, long long MMM = MOD) {
  long long ret = 1;
  for (; b; b >>= 1, a = (a * a) % MMM)
    if (b & 1) ret = (ret * a) % MMM;
  return ret;
}
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
int ddx[] = {-1, -2, 1, -2, 2, -1, 2, 1}, ddy[] = {-2, -1, -2, 1, -1, 2, 1, 2};
int x[505], y[505];
int x1[505], y22[505], x2[505], y2[505];
int a[1505][1505];
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  for (int(i) = (0); (i) <= (k - 1); (i) += (1)) {
    scanf("%d%d", x + i, y + i);
    --x[i], --y[i];
  }
  int l = 0, r = 1e9;
  while (l <= r) {
    int mid = l + r >> 1;
    vector<int> vx = {-1, 0, n}, vy = {-1, 0, m};
    for (int(i) = (0); (i) <= (k - 1); (i) += (1)) {
      x1[i] = max(0, x[i] - mid);
      x2[i] = min(n, x[i] + mid + 1);
      y22[i] = max(0, y[i] - mid);
      y2[i] = min(m, y[i] + mid + 1);
      vx.push_back(x1[i]);
      vx.push_back(x2[i]);
      vy.push_back(y22[i]);
      vy.push_back(y2[i]);
    }
    sort(vx.begin(), vx.end());
    vx.resize(unique(vx.begin(), vx.end()) - vx.begin());
    sort(vy.begin(), vy.end());
    vy.resize(unique(vy.begin(), vy.end()) - vy.begin());
    int N = vx.size(), M = vy.size();
    for (int(i) = (1); (i) <= (N - 1); (i) += (1))
      for (int(j) = (1); (j) <= (M - 1); (j) += (1)) a[i][j] = 0;
    for (int(i) = (0); (i) <= (k - 1); (i) += (1)) {
      x1[i] = lower_bound(vx.begin(), vx.end(), x1[i]) - vx.begin();
      x2[i] = lower_bound(vx.begin(), vx.end(), x2[i]) - vx.begin();
      y22[i] = lower_bound(vy.begin(), vy.end(), y22[i]) - vy.begin();
      y2[i] = lower_bound(vy.begin(), vy.end(), y2[i]) - vy.begin();
      a[x1[i]][y22[i]]++;
      a[x2[i]][y22[i]]--;
      a[x1[i]][y2[i]]--;
      a[x2[i]][y2[i]]++;
    }
    for (int(i) = (1); (i) <= (N - 1); (i) += (1))
      for (int(j) = (1); (j) <= (M - 1); (j) += (1))
        a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
    int xx1 = 1000000005, xx2 = -1, yy1 = 1000000005, yy2 = -1;
    for (int(i) = (1); (i) <= (N - 2); (i) += (1))
      for (int(j) = (1); (j) <= (M - 2); (j) += (1)) {
        if (!a[i][j]) {
          xx1 = min(xx1, vx[i]), xx2 = max(xx2, vx[i + 1] - 1);
          yy1 = min(yy1, vy[j]), yy2 = max(yy2, vy[j + 1] - 1);
        }
      }
    if (xx2 - xx1 <= 2 * mid && yy2 - yy1 <= 2 * mid)
      r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d\n", l);
}
