#include <bits/stdc++.h>
using namespace std;
int bo[2000][2000], n, m, k, p1[100000], p2[100000];
set<int> s1, s2;
map<int, int> m1, m2;
struct arr {
  int x, y;
} a[100000];
int check(int x) {
  int len1 = 0, len2 = 0;
  s1.clear();
  s2.clear();
  m1.clear();
  m2.clear();
  for (int i = 1; i < k; i++) {
    s1.insert(max(a[i].x - x, 1));
    s1.insert(min(a[i].x + x + 1, n + 1));
    s2.insert(max(a[i].y - x, 1));
    s2.insert(min(a[i].y + x + 1, m + 1));
  }
  s1.insert(1);
  s2.insert(1);
  s1.insert(n);
  s2.insert(m);
  s1.insert(n + 1);
  s2.insert(m + 1);
  for (auto i : s1) m1[i] = ++len1, p1[len1] = i;
  for (auto i : s2) m2[i] = ++len2, p2[len2] = i;
  for (int i = 1; i <= len1; i++)
    for (int j = 1; j <= len2; j++) bo[i][j] = 0;
  for (int i = 1; i < k; i++) {
    int x11 = max(a[i].x - x, 1), x22 = min(a[i].x + x + 1, n + 1),
        y11 = max(a[i].y - x, 1), y22 = min(a[i].y + x + 1, m + 1);
    bo[m1[x11]][m2[y11]] += 1;
    bo[m1[x11]][m2[y22]] -= 1;
    bo[m1[x22]][m2[y11]] -= 1;
    bo[m1[x22]][m2[y22]] += 1;
  }
  int maxx = 0, maxy = 0, minx = n + 1, miny = m + 1;
  for (int i = 1; i <= len1; i++)
    for (int j = 1; j <= len2; j++) {
      bo[i][j] = bo[i][j] + bo[i - 1][j] + bo[i][j - 1] - bo[i - 1][j - 1];
      if (bo[i][j] <= 0 && p1[i] <= n && p2[j] <= m) {
        maxx = max(p1[i + 1] - 1, maxx);
        minx = min(p1[i], minx);
        maxy = max(p2[j + 1] - 1, maxy);
        miny = min(p2[j], miny);
      }
    }
  return max(maxy - miny + 1, maxx - minx + 1) <= x * 2 + 1;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  ++k;
  for (int i = 1; i < k; i++) scanf("%d%d", &a[i].x, &a[i].y);
  int l = -1, r = max(n, m), mid = (l + r) >> 1;
  do {
    if (check(mid))
      r = mid;
    else
      l = mid;
    mid = (l + r) >> 1;
  } while (l + 1 < r);
  printf("%d", r);
}
