#include <bits/stdc++.h>
using namespace std;
const int mx = 5e2 + 10;
const long long mod = 1e9 + 31;
mt19937 mtrand(time(0));
struct P {
  long long x, y;
} p[mx];
long long n, m;
int k;
int mp[mx * 2][mx * 2];
vector<long long> vecx, vecy;
bool check(long long mid) {
  vecx.clear(), vecy.clear();
  for (int i = 1; i <= k; ++i) {
    vecx.push_back(max(1ll, p[i].x - mid));
    vecx.push_back(min(n + 1, p[i].x + mid + 1));
    vecy.push_back(max(1ll, p[i].y - mid));
    vecy.push_back(min(m + 1, p[i].y + mid + 1));
  }
  vecx.push_back(1), vecx.push_back(n + 1);
  vecy.push_back(1), vecy.push_back(m + 1);
  sort(vecx.begin(), vecx.end());
  sort(vecy.begin(), vecy.end());
  vecx.erase(unique(vecx.begin(), vecx.end()), vecx.end());
  vecy.erase(unique(vecy.begin(), vecy.end()), vecy.end());
  for (int i = 1; i < vecx.size(); ++i)
    for (int j = 1; j < vecy.size(); ++j) mp[i][j] = 0;
  for (int i = 1; i <= k; ++i) {
    int x1 = lower_bound(vecx.begin(), vecx.end(), max(1ll, p[i].x - mid)) -
             vecx.begin() + 1;
    int x2 =
        lower_bound(vecx.begin(), vecx.end(), min(n + 1, p[i].x + mid + 1)) -
        vecx.begin() + 1;
    int y1 = lower_bound(vecy.begin(), vecy.end(), max(1ll, p[i].y - mid)) -
             vecy.begin() + 1;
    int y2 =
        lower_bound(vecy.begin(), vecy.end(), min(m + 1, p[i].y + mid + 1)) -
        vecy.begin() + 1;
    ++mp[x1][y1], ++mp[x2][y2], --mp[x1][y2], --mp[x2][y1];
  }
  long long xL, xR, yL, yR;
  xL = yL = 0x3f3f3f3f3f3f3f3f, xR = yR = -0x3f3f3f3f3f3f3f3f;
  for (int i = 1; i < vecx.size(); ++i) {
    for (int j = 1; j < vecy.size(); ++j) {
      mp[i][j] += mp[i - 1][j] + mp[i][j - 1] - mp[i - 1][j - 1];
      if (!mp[i][j]) {
        xL = min(xL, vecx[i - 1]);
        xR = max(xR, vecx[i]);
        yL = min(yL, vecy[j - 1]);
        yR = max(yR, vecy[j]);
      }
    }
  }
  return xR - xL <= mid * 2 + 1 && yR - yL <= mid * 2 + 1;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= k; ++i) {
    scanf("%lld%lld", &p[i].x, &p[i].y);
  }
  long long l = 0, r = 2e9;
  while (l <= r) {
    long long mid = l + r >> 1;
    if (check(mid))
      r = mid - 1;
    else
      l = mid + 1;
  }
  cout << l << endl;
}
