#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 1000005;
struct Event {
  int x, l, r, o;
  bool operator<(const Event &p) const { return x == p.x ? o > p.o : x < p.x; }
} e[MAXN];
int n, m, k, tot;
int x[MAXN], y[MAXN];
int yy[MAXN], cnt;
int cov[MAXN];
bool check(int d) {
  cnt = tot = 0;
  yy[cnt++] = 1;
  yy[cnt++] = m;
  e[tot++] = (Event){1, 1, m + 1, 0};
  e[tot++] = (Event){n, 1, m + 1, 0};
  memset(cov, 0, sizeof cov);
  for (int i = (0); i < (k); i++) {
    e[tot++] = (Event){max(1, x[i] - d), 1, 1, 0};
    e[tot++] = (Event){max(1, x[i] - d + 1), max(1, y[i] - d + 1),
                       min(m + 1, y[i] + d), 1};
    e[tot++] = (Event){min(n + 1, x[i] + d), max(1, y[i] - d + 1),
                       min(m + 1, y[i] + d), -1};
  }
  for (int i = (0); i < (tot); i++) {
    yy[cnt++] = e[i].l;
    yy[cnt++] = e[i].r;
    if (e[i].l > 1) yy[cnt++] = e[i].l - 1;
  }
  sort(yy, yy + cnt);
  cnt = unique(yy, yy + cnt) - yy;
  for (int i = (0); i < (tot); i++) {
    e[i].l = lower_bound(yy, yy + cnt, e[i].l) - yy;
    e[i].r = lower_bound(yy, yy + cnt, e[i].r) - yy;
  }
  sort(e, e + tot);
  int mx[2], my[2];
  mx[0] = mx[1] = -1, my[0] = my[1] = -1;
  int t = 0;
  for (int i = 0; i < tot; i++) {
    for (int j = (e[i].l); j < (e[i].r); j++) cov[j] += e[i].o;
    if (i == tot - 1 || e[i].x != e[i + 1].x)
      for (int j = (0); j < (cnt); j++)
        if (!cov[j]) {
          if (e[i].x == n + 1) break;
          if (yy[j] == m + 1) break;
          if (mx[0] == -1)
            mx[0] = mx[1] = e[i].x;
          else
            mx[0] = min(mx[0], e[i].x), mx[1] = max(mx[1], e[i].x);
          if (my[0] == -1)
            my[0] = my[1] = yy[j];
          else
            my[0] = min(my[0], yy[j]), my[1] = max(my[1], yy[j]);
        }
  }
  return mx[1] == -1 ||
         ((mx[1] - mx[0] + 1) / 2 < d && (my[1] - my[0] + 1) / 2 < d);
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = (0); i < (k); i++) {
    scanf("%d%d", x + i, y + i);
  }
  int l = 0, r = 1e9 + 7;
  while (r - l > 1) {
    int m = (l + r) >> 1;
    if (check(m))
      r = m;
    else
      l = m;
  }
  printf("%d\n", r - 1);
  return 0;
}
