#include <bits/stdc++.h>
using namespace std;
int qmin(int a, int b) { return (a < b) ? a : b; }
int qmax(int a, int b) { return (a > b) ? a : b; }
int n, m, k;
int x[555], y[555];
int xl[555], xr[555], yl[555], yr[555];
set<int> stx, sty;
map<int, int> mpx;
int xpos[1010];
vector<int> l[1010], r[1010];
multiset<pair<int, int> > y_seg_l;
bool check(int now) {
  for (int i = 0; i < 1001; i++) l[i].clear(), r[i].clear();
  for (int i = 0; i < k; i++)
    xl[i] = qmax(x[i] - now, 1), xr[i] = qmin(x[i] + now, n),
    yl[i] = qmax(y[i] - now, 1), yr[i] = qmin(y[i] + now, m);
  stx.clear(), sty.clear();
  for (int i = 0; i < k; i++) stx.insert(xl[i]), stx.insert(xr[i] + 1);
  stx.insert(1), stx.insert(n + 1);
  int cnt = 0;
  for (set<int>::iterator it = stx.begin(); it != stx.end(); it++, cnt++)
    mpx[*it] = cnt, xpos[cnt] = *it;
  for (int i = 0; i < k; i++)
    l[mpx[xl[i]]].push_back(i), r[mpx[xr[i] + 1]].push_back(i);
  y_seg_l.clear();
  int xxl = n + 1, xxr = 0, yyl = m + 1, yyr = 0;
  y_seg_l.insert(make_pair(0, 0));
  y_seg_l.insert(make_pair(m + 1, m + 1));
  for (int i = 0; i < cnt - 1; i++) {
    for (int j = 0; j < (int)r[i].size(); j++) {
      multiset<pair<int, int> >::iterator it =
          y_seg_l.lower_bound(make_pair(yl[r[i][j]], yr[r[i][j]]));
      y_seg_l.erase(it);
    }
    for (int j = 0; j < (int)l[i].size(); j++)
      y_seg_l.insert(make_pair(yl[l[i][j]], yr[l[i][j]]));
    int nr = 0;
    int nyl = m + 1, nyr = 0;
    for (set<pair<int, int> >::iterator it = y_seg_l.begin();
         it != y_seg_l.end(); it++) {
      if (it->first > nr + 1)
        nyl = qmin(nyl, nr + 1), nyr = qmax(nyr, it->first - 1);
      nr = qmax(nr, it->second);
    }
    if (nyr > 0) {
      xxl = qmin(xxl, xpos[i]);
      xxr = qmax(xxr, xpos[i + 1] - 1);
    }
    yyl = qmin(yyl, nyl);
    yyr = qmax(yyr, nyr);
  }
  if (xxr == 0) return 1;
  return ((xxr - xxl + 1) <= (now + now + 1)) &&
         ((yyr - yyl + 1) <= (now + now + 1));
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> k;
  for (int i = 0; i < k; i++) cin >> x[i] >> y[i];
  int lb = 0, ub = 1e9;
  while (lb <= ub) {
    int mid = (lb + ub) >> 1;
    if (check(mid))
      ub = mid - 1;
    else
      lb = mid + 1;
  }
  cout << lb << endl;
  return 0;
}
