#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > p;
long long n, m, k, xi, yi;
long long INF = 1e18;
bool checker(long long number) {
  vector<long long> ye, xe;
  vector<pair<long long, long long> > px, py;
  for (long long i = 0; i < k; i++) {
    px.push_back(make_pair(p[i].first, p[i].second));
    py.push_back(make_pair(p[i].second, p[i].first));
  }
  sort(px.begin(), px.end());
  sort(py.begin(), py.end());
  for (long long i = 0; i < p.size(); i++) {
    ye.push_back(max((long long)1, p[i].second - number));
    ye.push_back(min(m, ye.back() + 1));
    ye.push_back(max((long long)1, ye.back() - 2));
    ye.push_back(min(m, p[i].second + number));
    ye.push_back(min(m, ye.back() + 1));
    ye.push_back(max((long long)1, ye.back() - 2));
  }
  sort(ye.begin(), ye.end());
  long long l = INF;
  long long r = -INF;
  if (ye[0] != 1)
    l = 1;
  else {
    for (long long j = 0; j < ye.size(); j++) {
      long long mp = 0;
      for (long long i = 0; i < px.size(); i++) {
        long long f = max((long long)1, px[i].second - number);
        long long s = min(m, px[i].second + number);
        if (ye[j] < f || ye[j] > s) continue;
        if (px[i].first - number > mp + 1)
          break;
        else {
          mp = max(mp, px[i].first + number);
        }
      }
      if (mp >= n) continue;
      l = ye[j];
      break;
    }
  }
  if (ye.back() != m)
    r = m;
  else {
    for (long long j = ye.size() - 1; j >= 0; j--) {
      long long mp = n + 1;
      for (long long i = px.size() - 1; i >= 0; i--) {
        long long f = max((long long)1, px[i].second - number);
        long long s = min(m, px[i].second + number);
        if (ye[j] < f || ye[j] > s) continue;
        if (px[i].first + number < mp - 1)
          break;
        else {
          mp = min(mp, px[i].first - number);
        }
      }
      if (mp <= 1) continue;
      r = ye[j];
      break;
    }
  }
  if (l == INF) return true;
  if (r - l > 2 * number) return false;
  for (long long i = 0; i < p.size(); i++) {
    xe.push_back(max((long long)1, p[i].first - number));
    xe.push_back(min(n, xe.back() + 1));
    xe.push_back(max((long long)1, xe.back() - 2));
    xe.push_back(min(n, p[i].first + number));
    xe.push_back(min(n, xe.back() + 1));
    xe.push_back(max((long long)1, xe.back() - 2));
  }
  sort(xe.begin(), xe.end());
  l = INF;
  r = -INF;
  if (xe[0] != 1)
    l = 1;
  else {
    for (long long j = 0; j < xe.size(); j++) {
      long long mp = 0;
      for (long long i = 0; i < py.size(); i++) {
        long long f = max((long long)1, py[i].second - number);
        long long s = min(n, py[i].second + number);
        if (xe[j] < f || xe[j] > s) continue;
        if (py[i].first - number > mp + 1)
          break;
        else {
          mp = max(mp, py[i].first + number);
        }
      }
      if (mp >= m) continue;
      l = xe[j];
      break;
    }
  }
  if (xe.back() != n)
    r = n;
  else {
    for (long long j = xe.size() - 1; j >= 0; j--) {
      long long mp = m + 1;
      for (long long i = py.size() - 1; i >= 0; i--) {
        long long f = max((long long)1, py[i].second - number);
        long long s = min(n, py[i].second + number);
        if (xe[j] < f || xe[j] > s) continue;
        if (py[i].first + number < mp - 1)
          break;
        else {
          mp = min(mp, py[i].first - number);
        }
      }
      if (mp <= 1) continue;
      r = xe[j];
      break;
    }
  }
  if (r - l > 2 * number) return false;
  return true;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m >> k;
  for (long long i = 0; i < k; i++) {
    cin >> xi >> yi;
    p.push_back(make_pair(xi, yi));
  }
  sort(p.begin(), p.end());
  long long left = -1;
  long long right = 1e10;
  while (right - left > 1) {
    long long mid = (left + right) / 2;
    bool res = checker(mid);
    if (res)
      right = mid;
    else
      left = mid;
  }
  cout << right << endl;
  return 0;
}
