#include <bits/stdc++.h>
using namespace std;
const long long inf = INT_MAX, df = 2555;
vector<long long> st, ch;
long long i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, a[df], b[df],
    sum[df][df];
inline long long read() {
  long long x = 0, y = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') y = (ch == '-') ? -1 : 1, ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x * y;
}
inline long long getid(long long x, vector<long long> &st) {
  return lower_bound(st.begin(), st.end(), x) - st.begin() + 1;
}
bool chk(long long x) {
  st.clear(), ch.clear();
  memset(sum, 0, sizeof(sum));
  for (long long i = (1); i <= (k); ++i) {
    long long up = a[i] - x, down = a[i] + x + 1, le = b[i] - x,
              rig = b[i] + x + 1;
    up = max(up, 1ll), le = max(le, 1ll), down = min(down, n + 1),
    rig = min(rig, m + 1);
    st.push_back(up), st.push_back(down);
    ch.push_back(le), ch.push_back(rig);
  }
  st.push_back(1), st.push_back(n + 1), ch.push_back(1), ch.push_back(m + 1);
  sort(st.begin(), st.end()), sort(ch.begin(), ch.end());
  st.erase(unique(st.begin(), st.end()), st.end()),
      ch.erase(unique(ch.begin(), ch.end()), ch.end());
  for (long long i = (1); i <= (k); ++i) {
    long long up = getid(max(a[i] - x, 1ll), st),
              down = getid(min(n + 1, a[i] + x + 1), st),
              le = getid(max(b[i] - x, 1ll), ch),
              rig = getid(min(m + 1, b[i] + x + 1), ch);
    ++sum[up][le], ++sum[down][rig], --sum[up][rig], --sum[down][le];
  }
  long long xmin = inf, ymin = inf, xmax = -inf, ymax = -inf;
  for (long long i = (1); i <= (st.size() - 1); ++i)
    for (long long j = (1); j <= (ch.size() - 1); ++j) {
      sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
      if (!sum[i][j])
        xmin = min(xmin, i), ymin = min(ymin, j), xmax = max(xmax, i),
        ymax = max(ymax, j);
    }
  if (xmin == inf) return 1;
  xmin = st[xmin - 1], ymin = ch[ymin - 1], xmax = st[xmax] - 1,
  ymax = ch[ymax] - 1;
  if (max(xmax - xmin, ymax - ymin) <= 2 * x) return 1;
  return 0;
}
int main() {
  n = read(), m = read(), k = read();
  for (long long i = (1); i <= (k); ++i) a[i] = read(), b[i] = read();
  long long l = 0, r = max(n, m) / 2, ans = 0;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (chk(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  return printf("%lld\n", ans), 0;
}
