#include <bits/stdc++.h>
using namespace std;
const int mx = 555;
int rs[mx], cs[mx];
int n, m, k;
int lft, rht, upw, dwn;
int rad;
void checkRow(int rw) {
  vector<pair<int, int> > all;
  for (int i = 0; i < k; i++) {
    int u = rs[i] - rad, d = rs[i] + rad;
    int l = max(0, cs[i] - rad), r = min(m - 1, cs[i] + rad);
    if (u <= rw && rw <= d) all.push_back({l, r});
  }
  sort(all.begin(), all.end());
  int bef = -1;
  bool ok = false;
  for (int i = 0; i < int(all.size()); i++) {
    if (all[i].first > bef + 1) ok = true;
    bef = max(bef, all[i].second);
  }
  if (bef < m - 1) ok = true;
  if (ok) {
    upw = min(upw, rw);
    dwn = max(dwn, rw);
  }
}
void checkCol(int cl) {
  vector<pair<int, int> > all;
  for (int i = 0; i < k; i++) {
    int l = cs[i] - rad, r = cs[i] + rad;
    int u = max(0, rs[i] - rad), d = min(n - 1, rs[i] + rad);
    if (l <= cl && cl <= r) all.push_back({u, d});
  }
  sort(all.begin(), all.end());
  int bef = -1;
  bool ok = false;
  for (int i = 0; i < int(all.size()); i++) {
    if (all[i].first > bef + 1) ok = true;
    bef = max(bef, all[i].second);
  }
  if (bef < n - 1) ok = true;
  if (ok) {
    lft = min(lft, cl);
    rht = max(rht, cl);
  }
}
bool can() {
  lft = n, rht = -1, upw = n, dwn = -1;
  checkCol(0);
  checkCol(m - 1);
  for (int i = 0; i < k; i++) {
    if (cs[i] + rad + 1 < m) checkCol(cs[i] + rad + 1);
    if (cs[i] - rad - 1 >= 0) checkCol(cs[i] - rad - 1);
  }
  checkRow(0);
  checkRow(n - 1);
  for (int i = 0; i < k; i++) {
    if (rs[i] + rad + 1 < n) checkRow(rs[i] + rad + 1);
    if (rs[i] - rad - 1 >= 0) checkRow(rs[i] - rad - 1);
  }
  return (rht - lft + 1 <= rad + rad + 1 && dwn - upw + 1 <= rad + rad + 1);
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < k; i++) {
    cin >> rs[i] >> cs[i];
    --rs[i], --cs[i];
  }
  int li = 0, ls = max(n, m), ans = -1;
  while (li <= ls) {
    rad = (li + ls) >> 1;
    if (can())
      ans = rad, ls = rad - 1;
    else
      li = rad + 1;
  }
  cout << ans << endl;
  return 0;
}
