#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
int n, m, k, sz_x, sz_y;
int x[maxn], y[maxn], xl[maxn], xr[maxn], yl[maxn], yr[maxn], sum[maxn];
vector<int> num_x, num_y, eve[maxn];
void update(int l, int r, int val) {
  for (int i = l; i < r; i++) sum[i] += val;
}
bool check(int r) {
  num_x.clear();
  num_y.clear();
  num_x.push_back(1);
  num_x.push_back(n + 1);
  num_y.push_back(1);
  num_y.push_back(m + 1);
  for (int i = 1; i <= (k); i++) {
    xl[i] = max(1, x[i] - r);
    xr[i] = min(n, x[i] + r) + 1;
    yl[i] = max(1, y[i] - r), yr[i] = min(m, y[i] + r) + 1;
    num_x.push_back(xl[i]);
    num_x.push_back(xr[i]);
    num_y.push_back(yl[i]);
    num_y.push_back(yr[i]);
  }
  sort(num_x.begin(), num_x.end());
  num_x.resize(unique(num_x.begin(), num_x.end()) - num_x.begin());
  sz_x = int(num_x.size());
  sort(num_y.begin(), num_y.end());
  num_y.resize(unique(num_y.begin(), num_y.end()) - num_y.begin());
  sz_y = int(num_y.size());
  for (int i = 1; i <= (sz_x); i++) eve[i].clear();
  for (int i = 1; i <= (sz_y); i++) sum[i] = 0;
  for (int i = 1; i <= (k); i++) {
    xl[i] = lower_bound(num_x.begin(), num_x.end(), xl[i]) - num_x.begin() + 1;
    xr[i] = lower_bound(num_x.begin(), num_x.end(), xr[i]) - num_x.begin() + 1;
    yl[i] = lower_bound(num_y.begin(), num_y.end(), yl[i]) - num_y.begin() + 1;
    yr[i] = lower_bound(num_y.begin(), num_y.end(), yr[i]) - num_y.begin() + 1;
    eve[xl[i]].push_back(i);
    eve[xr[i]].push_back(-i);
  }
  int mn_x = n + 1, mx_x = 0, mn_y = m + 1, mx_y = 0;
  for (int i = 1; i <= (sz_x - 1); i++) {
    for (int j = 0; j < (int(eve[i].size())); j++) {
      int id = eve[i][j];
      if (id > 0)
        update(yl[id], yr[id], 1);
      else
        update(yl[-id], yr[-id], -1);
    }
    int curx_l = num_x[i - 1], curx_r = num_x[i] - 1;
    for (int j = 1; j <= (sz_y - 1); j++) {
      int cury_l = num_y[j - 1], cury_r = num_y[j] - 1;
      if (!sum[j]) {
        mn_x = min(mn_x, curx_l);
        mx_x = max(mx_x, curx_r);
        mn_y = min(mn_y, cury_l);
        mx_y = max(mx_y, cury_r);
      }
    }
  }
  return mx_x - mn_x <= 2 * r && mx_y - mn_y <= 2 * r;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= (k); i++) scanf("%d%d", &x[i], &y[i]);
  int l = -1, r = max(n, m);
  while (r - l > 1) {
    int mid = l + r >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  printf("%d\n", r);
  return 0;
}
