#include <bits/stdc++.h>
using namespace std;
int n, m, k, pref[6006][6006];
vector<pair<int, int> > v;
vector<int> x, y;
void addX(int v) {
  x.push_back(v);
  x.push_back(min(v, n + 1));
  x.push_back(max(1, v - 1));
}
void addY(int v) {
  y.push_back(v);
  y.push_back(min(v, m + 1));
  y.push_back(max(1, v - 1));
}
bool check(int t) {
  x.clear();
  y.clear();
  x.push_back(1);
  x.push_back(n);
  x.push_back(n + 1);
  y.push_back(1);
  y.push_back(m);
  y.push_back(m + 1);
  for (int i = 0; i < k; ++i) {
    int xL = max(1, v[i].first - t), xR = min(n + 1, v[i].first + t + 1),
        yL = max(1, v[i].second - t), yR = min(m + 1, v[i].second + t + 1);
    addX(xL);
    addX(xR);
    addY(yL);
    addY(yR);
  }
  sort(x.begin(), x.end());
  x.erase(unique(x.begin(), x.end()), x.end());
  sort(y.begin(), y.end());
  y.erase(unique(y.begin(), y.end()), y.end());
  for (int i = 0; i <= x.size() + 1; ++i) {
    for (int j = 0; j <= y.size() + 1; ++j) {
      pref[i][j] = 0;
    }
  }
  for (int i = 0; i < k; ++i) {
    int xL = lower_bound(x.begin(), x.end(), max(1, v[i].first - t)) -
             x.begin() + 1,
        yL = lower_bound(y.begin(), y.end(), max(1, v[i].second - t)) -
             y.begin() + 1,
        xR = lower_bound(x.begin(), x.end(), min(n, v[i].first + t) + 1) -
             x.begin() + 1,
        yR = lower_bound(y.begin(), y.end(), min(m, v[i].second + t) + 1) -
             y.begin() + 1;
    ++pref[xL][yL];
    --pref[xL][yR];
    --pref[xR][yL];
    ++pref[xR][yR];
  }
  int mnX = x.size() + 1, mxX = 0, mnY = y.size() + 1, mxY = 0;
  for (int i = 1; i < x.size(); ++i) {
    for (int j = 1; j < y.size(); ++j) {
      pref[i][j] += pref[i][j - 1] + pref[i - 1][j] - pref[i - 1][j - 1];
      if (!pref[i][j]) {
        mnX = min(mnX, i);
        mnY = min(mnY, j);
        mxX = max(mxX, i);
        mxY = max(mxY, j);
      }
    }
  }
  if (mnX > mxX) {
    return 1;
  }
  mnX = x[mnX - 1];
  mxX = x[mxX - 1];
  mnY = y[mnY - 1];
  mxY = y[mxY - 1];
  int dist = max(mxX - mnX, mxY - mnY);
  if (dist & 1) {
    ++dist;
  }
  int need = (dist >> 1);
  return need <= t;
}
int BSFind(int low, int high) {
  int res = 2e9;
  while (low <= high) {
    int mid = low + ((high - low) >> 1);
    if (check(mid)) {
      high = mid - 1;
      res = mid;
    } else {
      low = mid + 1;
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m >> k;
  for (int i = 0; i < k; ++i) {
    int a, b;
    cin >> a >> b;
    v.push_back({a, b});
  }
  cout << BSFind(0, 1e9 + 9);
  return 0;
}
