#include <bits/stdc++.h>
using namespace std;
const int N = 505;
const int INF = 0x3f3f3f3f;
int n, m, k, A[N], B[N], a[2 * N], b[2 * N], t1, t2, p[2 * N][2 * N];
inline void ckmin(int& x, int y) { x = min(x, y); }
inline void ckmax(int& x, int y) { x = max(x, y); }
inline bool check(int t) {
  memset(a, 0, sizeof(a)), memset(b, 0, sizeof(b)), t1 = 0, t2 = 0,
                                                    memset(p, 0, sizeof(p));
  a[t1++] = 0, a[t1++] = n;
  for (int i = (1), iend = (k); i <= iend; i++)
    a[t1++] = max(0, A[i] - t), a[t1++] = min(n, A[i] + t + 1);
  b[t2++] = 0, b[t2++] = m;
  for (int i = (1), iend = (k); i <= iend; i++)
    b[t2++] = max(0, B[i] - t), b[t2++] = min(m, B[i] + t + 1);
  sort(a, a + t1), t1 = unique(a, a + t1) - a;
  sort(b, b + t2), t2 = unique(b, b + t2) - b;
  for (int i = (1), iend = (k); i <= iend; i++) {
    int al = lower_bound(a, a + t1, max(A[i] - t, 0)) - a;
    int ar = lower_bound(a, a + t1, min(A[i] + t + 1, n)) - a;
    int bl = lower_bound(b, b + t2, max(B[i] - t, 0)) - b;
    int br = lower_bound(b, b + t2, min(B[i] + t + 1, m)) - b;
    for (int i = (al), iend = (ar - 1); i <= iend; i++)
      for (int j = (bl), jend = (br - 1); j <= jend; j++) p[i][j] = 1;
  }
  int al = INF, ar = 0, bl = INF, br = 0, tag = 0;
  for (int i = (0), iend = (t1 - 2); i <= iend; i++)
    for (int j = (0), jend = (t2 - 2); j <= jend; j++)
      if (!p[i][j])
        ckmin(al, i), ckmax(ar, i), ckmin(bl, j), ckmax(br, j), tag = 1;
  if (!tag) return 1;
  return (a[ar + 1] - a[al] <= 2 * t + 1) && (b[br + 1] - b[bl] <= 2 * t + 1);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m >> k;
  for (int i = (1), iend = (k); i <= iend; i++)
    cin >> A[i] >> B[i], A[i]--, B[i]--;
  int l = 0, r = max(n, m), ans = r;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d", ans);
  return 0;
}
