#include <bits/stdc++.h>
using namespace std;
struct Node {
  int l, r, v, ret;
  Node() : l(0), r(0), v(0), ret(0) {}
} st[2000000];
struct event {
  int first, l, r, tp;
} ev[555 * 4];
bool operator<(event a, event b) { return a.first < b.first; }
int n, m, k, xa, xb, ya, yb, ans, ptr, root, INF = 1e9 + 100;
pair<int, int> vet[555];
int novo() {
  st[ptr] = Node();
  return ptr++;
}
void upd(int b, int l, int r, int first, int second, int ad) {
  assert(b);
  if (second < l || r < first) return;
  if (ad) {
    if (first <= l && r <= second) {
      st[b].ret++;
      st[b].v = r - l + 1;
      return;
    }
  } else {
    if (first <= l && r <= second) {
      st[b].ret--;
      if (!st[b].ret)
        st[b].v = st[st[b].l].v + st[st[b].r].v;
      else
        st[b].v = r - l + 1;
      return;
    }
  }
  int mid = (l + r) >> 1;
  if (!st[b].l) st[b].l = novo();
  upd(st[b].l, l, mid, first, second, ad);
  if (!st[b].r) st[b].r = novo();
  upd(st[b].r, mid + 1, r, first, second, ad);
  if (!st[b].ret) st[b].v = st[st[b].l].v + st[st[b].r].v;
}
int maior(int b, int l, int r) {
  if (l > r) return -1;
  if (!b || !st[b].v) return r;
  if (r - l + 1 == st[b].v) return -1;
  int ret = -1, mid = (l + r) >> 1;
  ret = max(ret, maior(st[b].r, mid + 1, r));
  if (ret < 0) ret = max(ret, maior(st[b].l, l, mid));
  return ret;
}
int menor(int b, int l, int r) {
  if (l > r) return INF;
  if (!b || !st[b].v) return l;
  if (r - l + 1 == st[b].v) return INF;
  int ret = INF, mid = (l + r) >> 1;
  ret = min(ret, menor(st[b].l, l, mid));
  if (ret > 1e9) ret = min(ret, menor(st[b].r, mid + 1, r));
  return ret;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int(i) = (0); (i) < (k); (i)++)
    scanf("%d%d", &vet[i].first, &vet[i].second);
  sort(vet, vet + k);
  int l = 0, r = 1e9, mid;
  while (l <= r) {
    xa = INF, xb = -1, ya = INF, yb = -1, ptr = 1;
    root = novo();
    mid = (l + r) >> 1;
    int cnt = 0;
    ev[cnt].first = 1;
    ev[cnt].tp = 0;
    cnt++;
    ev[cnt].first = n;
    ev[cnt].tp = 0;
    cnt++;
    for (int(i) = (0); (i) < (k); (i)++) {
      int xl = max(1, vet[i].first - mid), xr = min(n, vet[i].first + mid),
          yl = max(1, vet[i].second - mid), yr = min(m, vet[i].second + mid);
      if (xl > 1) {
        ev[cnt].first = xl - 1;
        ev[cnt].tp = 0;
        cnt++;
      }
      if (xr < n) {
        ev[cnt].first = xr + 1, ev[cnt].l = yl, ev[cnt].r = yr, ev[cnt].tp = 2;
        cnt++;
      }
      ev[cnt].first = xl, ev[cnt].l = yl, ev[cnt].r = yr, ev[cnt].tp = 1;
      cnt++;
    }
    sort(ev, ev + cnt);
    for (int(i) = (0); (i) < (cnt); (i)++) {
      int first = ev[i].first, l = ev[i].l, r = ev[i].r, tp = ev[i].tp;
      if (tp == 1) upd(root, 1, m, l, r, 1);
      if (tp == 2) upd(root, 1, m, l, r, 0);
      if (i + 1 < cnt && ev[i + 1].first == ev[i].first) continue;
      int yr = maior(root, 1, m), yl = menor(root, 1, m);
      if (yl <= yr) xa = min(xa, first), xb = max(xb, first);
      ya = min(ya, yl);
      yb = max(yb, yr);
    }
    if (xb - xa + 1 <= 2 * mid + 1 && yb - ya + 1 <= 2 * mid + 1)
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d\n", ans);
}
