#include <bits/stdc++.h>
using namespace std;
bool ch(long long time, vector<pair<long long, long long> > v, long long n,
        long long m) {
  set<long long> xi;
  xi.insert(1);
  xi.insert(n);
  multiset<pair<long long, long long> > timeline;
  for (auto j : v) {
    long long x = j.first;
    long long y = j.second;
    pair<long long, long long> lu, ld, ru, rd;
    lu = make_pair(max(x - time, 1ll), min(y + time, m));
    ld = make_pair(max(x - time, 1ll), max(y - time, 1ll));
    ru = make_pair(min(x + time, n), min(y + time, m));
    rd = make_pair(min(x + time, n), max(y - time, 1ll));
    xi.insert(lu.first - 1);
    xi.insert(ru.first + 1);
    xi.insert(ru.first);
    xi.insert(lu.first);
  }
  map<long long, long long> cn;
  long long c = 0;
  for (auto j : xi) {
    cn[j] = c++;
  }
  vector<pair<long long, long long> > ta[c];
  vector<pair<long long, long long> > td[c];
  for (auto j : v) {
    long long x = j.first;
    long long y = j.second;
    pair<long long, long long> lu, ld, ru, rd;
    lu = make_pair(max(x - time, 1ll), min(y + time, m));
    ld = make_pair(max(x - time, 1ll), max(y - time, 1ll));
    ru = make_pair(min(x + time, n), min(y + time, m));
    rd = make_pair(min(x + time, n), max(y - time, 1ll));
    ta[cn[lu.first]].push_back(make_pair(ld.second, lu.second));
    td[cn[ru.first + 1]].push_back(make_pair(rd.second, ru.second));
  }
  long long xmini = n + 1;
  long long xmax = 0;
  long long ymini = m + 1;
  long long ymax = 0;
  for (auto j : xi) {
    if (j == 0 || j == n + 1) continue;
    for (auto ja : td[cn[j]]) {
      timeline.erase(timeline.find(ja));
    }
    for (auto ja : ta[cn[j]]) {
      timeline.insert(ja);
    }
    long long miss = 0;
    long long end = 0;
    for (auto ja : timeline) {
      if (ja.first > end + 1) {
        miss = 1;
        ymini = min(ymini, end + 1);
        ymax = max(ymax, ja.first - 1);
        end = ja.second;
      } else
        end = max(end, ja.second);
    }
    if (end != m) {
      miss = 1;
      ymini = min(ymini, end + 1);
      ymax = max(ymax, m);
    }
    if (miss) {
      xmini = min(xmini, j);
      xmax = max(xmax, j);
    }
  }
  long long side = 2 * time + 1;
  if (ymax == 0) return true;
  if ((xmax - xmini + 1) <= side && (ymax - ymini + 1) <= side) return true;
  return false;
}
int main() {
  long long n, m, k;
  cin >> n >> m >> k;
  long long in = 0, fin = max(n, m) + 1;
  vector<pair<long long, long long> > v;
  for (long long i = 0; i < k; i++) {
    long long x, y;
    cin >> x >> y;
    v.push_back(make_pair(x, y));
  }
  long long me = fin;
  while (fin >= in) {
    long long mid = (fin + in) / 2ll;
    if (ch(mid, v, n, m)) {
      fin = mid - 1;
      me = min(me, mid);
    } else
      in = mid + 1;
  }
  cout << me << endl;
  return 0;
}
