#include <bits/stdc++.h>
using namespace std;
const int TSIZE = 2048;
int segtree[TSIZE * 2], prop[TSIZE * 2];
void seg_relax(int nod, int l, int r) {
  if (prop[nod] == 0) return;
  if (l < r) {
    segtree[nod << 1] += prop[nod];
    prop[nod << 1] += prop[nod];
    segtree[nod << 1 | 1] += prop[nod];
    prop[nod << 1 | 1] += prop[nod];
  }
  prop[nod] = 0;
}
int seg_query(int nod, int l, int r, int pt) {
  if (l == r) return segtree[nod];
  if (segtree[nod]) return 1;
  seg_relax(nod, l, r);
  int m = (l + r) >> 1;
  if (pt <= m)
    return seg_query(nod << 1, l, m, pt);
  else
    return seg_query(nod << 1 | 1, m + 1, r, pt);
}
void seg_update(int nod, int l, int r, int s, int e, int val) {
  if (r < s || e < l) return;
  if (s <= l && r <= e) {
    segtree[nod] += val;
    prop[nod] += val;
    return;
  }
  seg_relax(nod, l, r);
  int m = (l + r) >> 1;
  seg_update(nod << 1, l, m, s, e, val);
  seg_update(nod << 1 | 1, m + 1, r, s, e, val);
  segtree[nod] = min(segtree[nod << 1], segtree[nod << 1 | 1]);
}
int bx[505], by[505];
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < k; i++) scanf("%d%d", bx + i, by + i);
  int l = 0, r = 1e9, ans = -1;
  while (r >= l) {
    int c = (l + r) / 2;
    memset(segtree, 0, sizeof(segtree));
    memset(prop, 0, sizeof(prop));
    vector<int> xs, ys;
    ys.push_back(1);
    ys.push_back(m);
    map<int, vector<pair<int, int>>> add, sub;
    map<int, int> yti;
    for (int i = 0; i < k; i++) {
      int yl = by[i] - c, yr = by[i] + c;
      if (yl < 1) yl = 1;
      if (yr > m) yr = m;
      ys.push_back(yl);
      ys.push_back(yr);
      if (yl > 1) yl--;
      if (yr < m) yr++;
      ys.push_back(yl);
      ys.push_back(yr);
    }
    sort(ys.begin(), ys.end());
    ys.erase(unique(ys.begin(), ys.end()), ys.end());
    int ysz = ys.size();
    for (int i = 0; i < ysz; i++) yti[ys[i]] = i;
    for (int i = 0; i < k; i++) {
      int xl = bx[i] - c, xr = bx[i] + c + 1;
      int yl = by[i] - c, yr = by[i] + c;
      if (yl < 1) yl = 1;
      if (yr > m) yr = m;
      if (xl < 1) xl = 1;
      add[xl].emplace_back(yti[yl], yti[yr]);
      xs.push_back(xl);
      if (xr <= n) {
        sub[xr].emplace_back(yti[yl], yti[yr]);
        xs.push_back(xr);
      }
    }
    xs.push_back(1);
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
    int xsz = xs.size();
    xs.push_back(n + 1);
    int bl = -1, br = -1, bu = -1, bd = -1;
    for (int z = 0; z < xsz; z++) {
      int x = xs[z];
      for (auto p : add[x]) seg_update(1, 1, ysz, p.first + 1, p.second + 1, 1);
      for (auto p : sub[x])
        seg_update(1, 1, ysz, p.first + 1, p.second + 1, -1);
      for (int i = 0; i < ysz; i++) {
        if (seg_query(1, 1, ysz, i + 1)) continue;
        if (bl < 0) bl = x;
        br = xs[z + 1];
        if (bu < 0 || i < bu) bu = i;
        if (i > bd) bd = i;
      }
    }
    int xd = br - bl, yd = 0, cv = 2 * c + 1;
    if (bu >= 0) {
      yd = ys[bd] - ys[bu] + 1;
    }
    if (xd > cv || yd > cv) {
      l = c + 1;
    } else {
      r = c - 1;
      ans = c;
    }
  }
  printf("%d\n", ans);
}
