#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > sx, sy;
vector<int> c, r;
int n, m, k;
bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }
bool cx(int c, int t) {
  int s = 1;
  for (int i = 0; i < (int)sx.size(); i++) {
    int tp = max(sx[i].first - t, 1);
    int bt = min(sx[i].first + t, n);
    int lf = max(sx[i].second - t, 1);
    int rg = min(sx[i].second + t, m);
    if (lf <= c && c <= rg) {
      if (tp > s) return 0;
      s = max(s, bt + 1);
    }
  }
  return s == n + 1;
}
bool cy(int r, int t) {
  int s = 1;
  for (int i = 0; i < (int)sy.size(); i++) {
    int tp = max(sy[i].first - t, 1);
    int bt = min(sy[i].first + t, n);
    int lf = max(sy[i].second - t, 1);
    int rg = min(sy[i].second + t, m);
    if (tp <= r && r <= bt) {
      if (lf > s) return 0;
      s = max(s, rg + 1);
    }
  }
  return s == m + 1;
}
bool check(int t) {
  int lf, rg, tp, bt;
  lf = tp = INT_MAX;
  rg = bt = INT_MIN;
  for (int i = 0; i < (int)sx.size(); i++) {
    c.push_back(max(sx[i].second - t - 1, 1));
    c.push_back(min(sx[i].second + t + 1, m));
    r.push_back(max(sx[i].first - t - 1, 1));
    r.push_back(min(sx[i].second + t + 1, n));
  }
  c.push_back(1);
  c.push_back(m);
  r.push_back(1);
  r.push_back(n);
  sort(c.begin(), c.end());
  c.erase(unique(c.begin(), c.end()), c.end());
  sort(r.begin(), r.end());
  r.erase(unique(r.begin(), r.end()), r.end());
  for (int i = 0; i < (int)c.size(); i++)
    if (!cx(c[i], t)) {
      lf = c[i];
      break;
    }
  for (int i = c.size() - 1; i >= 0; i--)
    if (!cx(c[i], t)) {
      rg = c[i];
      break;
    }
  if (lf > rg) return 1;
  for (int i = 0; i < (int)r.size(); i++)
    if (!cy(r[i], t)) {
      tp = r[i];
      break;
    }
  for (int i = r.size() - 1; i >= 0; i--)
    if (!cy(r[i], t)) {
      bt = r[i];
      break;
    }
  if (rg - lf <= 2 * t && bt - tp <= 2 * t) return 1;
  return 0;
}
int main() {
  scanf("%d %d", &n, &m);
  scanf("%d", &k);
  for (int i = 0; i < k; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    sx.push_back(make_pair(x, y));
    sy.push_back(make_pair(x, y));
  }
  sort(sx.begin(), sx.end());
  sort(sy.begin(), sy.end(), cmp);
  int lo = 0;
  int hg = 1e9;
  while (lo < hg) {
    int mid = (lo + hg) / 2;
    if (check(mid)) {
      hg = mid;
    } else
      lo = mid + 1;
  }
  cout << lo << endl;
}
