#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while ('0' <= c && c <= '9') {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return x;
}
int n, m, k;
struct node {
  int x, y;
} a[505];
int x[1010], y[1010], xx[1010], yy[1010];
int find(int a[], int x, int len) {
  int l = 1, r = len;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (a[mid] <= x)
      l = mid + 1;
    else
      r = mid - 1;
  }
  return r;
}
int d[1010][1010], s[1010][1010], b[1010][1010];
bool check(int t) {
  memset(d, 0, sizeof(d));
  memset(s, 0, sizeof(s));
  memset(b, 0, sizeof(b));
  for (int i = 1; i <= k; i++) {
    x[i] = max(1, a[i].x - t), x[k + i] = min(n, a[i].x + t);
    y[i] = max(1, a[i].y - t), y[k + i] = min(m, a[i].y + t);
  }
  x[k * 2 + 1] = 1, x[k * 2 + 2] = n;
  y[k * 2 + 1] = 1, y[k * 2 + 2] = m;
  sort(x + 1, x + k * 2 + 3), sort(y + 1, y + k * 2 + 3);
  int tot1 = 0, tot2 = 0;
  for (int i = 1; i <= k * 2 + 2; i++)
    if (x[i] != x[i - 1]) xx[++tot1] = x[i];
  for (int i = 1; i <= k * 2 + 2; i++)
    if (y[i] != y[i - 1]) yy[++tot2] = y[i];
  for (int i = 1; i <= k; i++) {
    int x1 = find(xx, max(1, a[i].x - t), tot1);
    int y1 = find(yy, max(1, a[i].y - t), tot2);
    int x2 = find(xx, min(n, a[i].x + t), tot1);
    int y2 = find(yy, min(m, a[i].y + t), tot2);
    d[x1][y1]++, d[x2][y1]--, d[x1][y2]--, d[x2][y2]++;
  }
  int up = n, down = 1, left = m, right = 1;
  for (int i = 1; i < tot1; i++)
    for (int j = 1; j < tot2; j++)
      s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + d[i][j];
  for (int i = 1; i < tot1; i++) {
    for (int j = 1; j < tot2; j++) s[i][j] = min(s[i][j], 1);
  }
  for (int i = 1; i < tot1; i++)
    for (int j = 1; j < tot2; j++)
      if (!s[i][j])
        if ((xx[i] + s[i - 1][j] < xx[i + 1] || xx[i] == n - 1) &&
            (yy[j] + s[i][j - 1] < yy[j + 1] || yy[j] == m - 1)) {
          if (xx[i] + s[i - 1][j] < xx[i + 1])
            up = min(up, xx[i] + s[i - 1][j]);
          down = max(down, xx[i + 1] - s[i + 1][j]);
          if (yy[j] + s[i][j - 1] < yy[j + 1])
            left = min(left, yy[j] + s[i][j - 1]);
          right = max(right, yy[j + 1] - s[i][j + 1]);
        }
  if (up == n && left == m && down == 1 && right == 1) return 1;
  if (max(down - up, right - left) <= t * 2) return 1;
  return 0;
}
int main() {
  n = read(), m = read(), k = read();
  for (int i = 1; i <= k; i++) a[i].x = read(), a[i].y = read();
  if (k + 1 == n * m) {
    printf("0");
    return 0;
  }
  int l = 1, r = max(n, m);
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  printf("%d", l);
  return 0;
}
