#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, t = 1, c;
  while (!isdigit(c = getchar()))
    if (c == '-') t = -1;
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  return x * t;
}
int n, m, k;
int posx[505], posy[505];
int xsign[1010], ysign[1010], cntx, cnty;
void GetRange(int x, int y, int &l, int &r, int &u, int &d, int X) {
  l = x - 1 - X, r = x + X, u = y - 1 - X, d = y + X;
  l = max(l, 0);
  u = max(u, 0);
  r = min(r, n);
  d = min(d, m);
}
bool Judge(int x) {
  int l, u, r, d;
  cntx = 0, cnty = 0;
  xsign[cntx++] = 0;
  xsign[cntx++] = n;
  ysign[cnty++] = 0;
  ysign[cnty++] = m;
  for (int i = 0; i < k; i++) {
    GetRange(posx[i], posy[i], l, r, u, d, x);
    xsign[cntx++] = l;
    xsign[cntx++] = r;
    ysign[cnty++] = u;
    ysign[cnty++] = d;
  }
  sort(xsign, xsign + cntx);
  sort(ysign, ysign + cnty);
  int ulim = 2147483647, llim = 2147483647, dlim = 0, rlim = 0;
  for (int i = 0; i < cnty - 1; i++) {
    if (ysign[i] == ysign[i + 1]) continue;
    int head = 0, tail = 0;
    for (int j = 0; j < cntx - 1; j++) {
      if (xsign[j] == xsign[j + 1]) continue;
      while (tail < k) {
        bool pass = 0;
        GetRange(posx[tail], posy[tail], l, r, u, d, x);
        if (u < ysign[i + 1] && d > ysign[i]) {
          if (l < xsign[j + 1]) pass = 1;
        } else
          pass = 1;
        if (pass)
          tail++;
        else
          break;
      }
      while (head < k) {
        bool pass = 0;
        GetRange(posx[head], posy[head], l, r, u, d, x);
        if (u < ysign[i + 1] && d > ysign[i]) {
          if (!(r > xsign[j])) pass = 1;
        } else
          pass = 1;
        if (pass)
          head++;
        else
          break;
      }
      if (head == tail) {
        rlim = max(rlim, xsign[j + 1]);
        llim = min(llim, xsign[j]);
        dlim = max(dlim, ysign[i + 1]);
        ulim = min(ulim, ysign[i]);
      }
    }
  }
  int maxv = max(rlim - llim, dlim - ulim);
  maxv >>= 1;
  return maxv <= x;
}
int main() {
  n = read(), m = read(), k = read();
  for (int i = 0; i < k; i++) posx[i] = read(), posy[i] = read();
  for (int i = 0; i < k; i++)
    for (int j = i + 1; j < k; j++)
      if (posx[j] < posx[i]) swap(posx[j], posx[i]), swap(posy[j], posy[i]);
  int L = 0, R = max(n, m);
  Judge(2);
  while (L < R) {
    int m = L + R >> 1;
    if (Judge(m))
      R = m;
    else
      L = m + 1;
  }
  printf("%d", L);
}
