#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') {
    f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
int i, j, k, m, n, s, t;
struct point {
  int x, y;
} a[501];
bitset<1001> bst[1001], tmp;
int b[1001], c[1001];
int check(int x) {
  int t1 = 0, t2 = 0;
  b[++t1] = 1;
  c[++t2] = 1;
  b[++t1] = n + 1;
  c[++t2] = m + 1;
  for (i = 1; i <= k; i++) {
    b[++t1] = max(a[i].x - x, 1);
    b[++t1] = min(a[i].x + x + 1, n + 1);
    c[++t2] = max(a[i].y - x, 1);
    c[++t2] = min(a[i].y + x + 1, m + 1);
  }
  sort(b + 1, b + t1 + 1);
  sort(c + 1, c + t2 + 1);
  int len1 = unique(b + 1, b + t1 + 1) - b - 1;
  int len2 = unique(c + 1, c + t2 + 1) - c - 1;
  for (i = 1; i <= len1; i++) bst[i].reset();
  for (i = 1; i <= k; i++) {
    int x1 = lower_bound(b + 1, b + len1 + 1, max(1, a[i].x - x)) - b;
    int x2 = lower_bound(b + 1, b + len1 + 1, min(n + 1, a[i].x + x + 1)) - b;
    int y3647 = lower_bound(c + 1, c + len2 + 1, max(1, a[i].y - x)) - c;
    int y2 = lower_bound(c + 1, c + len2 + 1, min(m + 1, a[i].y + x + 1)) - c;
    tmp.reset();
    for (j = y3647; j <= y2 - 1; j++) tmp[j] = 1;
    for (j = x1; j <= x2 - 1; j++) bst[j] |= tmp;
  }
  int max_x = 0, min_x = 1e9, max_y = 0, min_y = 1e9;
  for (i = 1; i < len1; i++)
    for (j = 1; j < len2; j++)
      if (bst[i][j] == 0)
        max_x = max(max_x, i), min_x = min(min_x, i), max_y = max(max_y, j),
        min_y = min(min_y, j);
  if (min_x == 1e9) return 1;
  return (b[max_x + 1] - b[min_x] - 1 <= 2 * x &&
          c[max_y + 1] - c[min_y] - 1 <= 2 * x);
}
int main() {
  read(n), read(m), read(k);
  for (i = 1; i <= k; i++) read(a[i].x), read(a[i].y);
  int l = 0, r = 1e9, ans;
  while (r >= l) {
    int mid = (l + r) / 2;
    if (check(mid))
      ans = mid, r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d", ans);
  return 0;
}
