#include <bits/stdc++.h>
using namespace std;
constexpr int inf32 = 0x3f3f3f3f;
constexpr long long inf64 = 0x3f3f3f3f3f3f3f3f;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  vector<pair<int, int> > a(k);
  for (int i = 0; i < (k); ++i)
    cin >> a[i].first >> a[i].second, --a[i].first, --a[i].second;
  auto check = [&](int mid) {
    vector<int> dx = {0, n}, dy = {0, m};
    for (int i = 0; i < (k); ++i) {
      dx.push_back(max(a[i].first - mid, 0));
      dx.push_back(min(a[i].first + mid + 1, n));
      dy.push_back(max(a[i].second - mid, 0));
      dy.push_back(min(a[i].second + mid + 1, m));
    }
    sort((dx).begin(), (dx).end()), sort((dy).begin(), (dy).end());
    dx.erase(unique((dx).begin(), (dx).end()), dx.end());
    dy.erase(unique((dy).begin(), (dy).end()), dy.end());
    int sn = (int)((dx).size()), sm = (int)((dy).size());
    vector<vector<int> > c(sn, vector<int>(sm, 0));
    for (int i = 0; i < (k); ++i) {
      int u = lower_bound((dx).begin(), (dx).end(), max(a[i].first - mid, 0)) -
              dx.begin();
      int d =
          lower_bound((dx).begin(), (dx).end(), min(a[i].first + mid + 1, n)) -
          dx.begin();
      int l = lower_bound((dy).begin(), (dy).end(), max(a[i].second - mid, 0)) -
              dy.begin();
      int r =
          lower_bound((dy).begin(), (dy).end(), min(a[i].second + mid + 1, m)) -
          dy.begin();
      ++c[u][l], --c[u][r];
      --c[d][l], ++c[d][r];
    }
    int u = sn - 2, d = 0, l = sm - 2, r = 0;
    for (int i = 0; i < (sn - 1); ++i)
      for (int j = 0; j < (sm - 1); ++j) {
        if (i) c[i][j] += c[i - 1][j];
        if (j) c[i][j] += c[i][j - 1];
        if (i && j) c[i][j] -= c[i - 1][j - 1];
        if (!c[i][j]) {
          u = min(u, i), d = max(d, i);
          l = min(l, j), r = max(r, j);
        }
      }
    if (dx[d + 1] - dx[u] > 2 * mid + 1) return false;
    if (dy[r + 1] - dy[l] > 2 * mid + 1) return false;
    return true;
  };
  int l = -1, r = 1e9 + 1;
  while (r - l > 1) {
    int mid = l + r >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  cout << r << '\n';
  return 0;
}
