#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "\n";
  err(++it, args...);
}
const double PI = acos(-1);
const double eps = (1e-9);
const long long int INF = (1e18);
const int M = (1e9) + 7;
const int N = 2050;
const int K = 5250;
int dp[N][N];
int n, m, k;
vector<pair<int, int> > fire;
int saare[2][N];
int val[2][N];
int last[2][N];
int sz[2];
void compress(int ind, int n) {
  vector<pair<int, int> > tp(n);
  int i, j, r;
  for (i = 0; i < n; i++) tp[i].first = saare[ind][i], tp[i].second = i;
  sort(tp.begin(), tp.end());
  i = 0, r = 1, j = 0;
  while (i < n) {
    while (j < n && tp[i].first == tp[j].first)
      saare[ind][tp[j].second] = r, j++;
    val[ind][r++] = tp[i].first;
    if (j < n && tp[i].first + 1 < tp[j].first)
      val[ind][r] = tp[i].first + 1, last[ind][r] = tp[j].first - 1, r++;
    i = j;
  }
  sz[ind] = r;
  return;
}
int build() {
  int i, j, x, y, a, b;
  for (i = 0; i < sz[0]; ++i) {
    for (j = 0; j < sz[1]; ++j) dp[i][j] = 0;
  }
  for (i = 0; i < k; ++i) {
    x = saare[0][i], y = saare[1][i];
    a = saare[0][i + k], b = saare[1][i + k];
    dp[x][y] += 1;
    dp[x][b + 1] -= 1;
    dp[a + 1][y] -= 1;
    dp[a + 1][b + 1] += 1;
  }
  for (i = 1; i < sz[0]; ++i) {
    for (j = 1; j < sz[1]; ++j)
      dp[i][j] += (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]);
  }
  x = n + 1, a = 0;
  y = m + 1, b = 0;
  for (i = 1; i < sz[0]; ++i) {
    for (j = 1; j < sz[1]; ++j) {
      if (dp[i][j] == 0) {
        x = min(x, val[0][i]);
        a = max(a, val[0][i]);
        a = max(a, last[0][i]);
        y = min(y, val[1][j]);
        b = max(b, val[1][j]);
        b = max(b, last[1][j]);
      }
    }
  }
  int z = max(0, max(a - x, b - y));
  return z;
}
int check(int t) {
  vector<pair<int, int> > point(2 * k);
  int i, x, y, a, b;
  for (i = 0; i < k; ++i) {
    tie(x, y) = fire[i];
    a = max(x - t, 1), b = max(y - t, 1);
    point[i] = {a, b};
    a = min(x + t, n), b = min(y + t, m);
    point[i + k] = {a, b};
  }
  for (i = 0; i < 2 * k; ++i) tie(saare[0][i], saare[1][i]) = point[i];
  int s = 2 * k;
  saare[0][s] = 1, saare[1][s] = 1, s++;
  saare[0][s] = n, saare[1][s] = m, s++;
  compress(0, s);
  compress(1, s);
  {
    string _s = "t";
    replace(_s.begin(), _s.end(), ',', ' ');
    stringstream _ss(_s);
    istream_iterator<string> _it(_ss);
    err(_it, t);
  };
  int z = build();
  return (z <= 2 * t);
}
void solve() {
  scanf("%d%d%d", &n, &m, &k);
  fire.resize(k);
  int i;
  for (i = 0; i < k; ++i) scanf("%d%d", &fire[i].first, &fire[i].second);
  int mid, l = 0, r = (max(n, m) / 2);
  while (l < r) {
    mid = ((l + r) >> 1);
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  printf("%d\n", l);
}
int main() {
  int t;
  t = 1;
  while (t--) solve();
}
