#include <bits/stdc++.h>
using namespace std;
int n, m, k;
pair<int, int> pkts[1000];
int mapa[3000][3000];
int Rmapx[3000];
int Rmapy[3000];
int dist(pair<int, int> a, int i) {
  return max(abs(pkts[i].first - Rmapx[a.first]),
             abs(pkts[i].second - Rmapy[a.second]));
}
bool query(int t) {
  map<int, int> Skx, Sky;
  set<int> Sx, Sy;
  Sx.insert(0);
  Sx.insert(n - 1);
  Sy.insert(0);
  Sy.insert(m - 1);
  for (int i = 0; i < k; ++i) {
    Sx.insert(pkts[i].first - t - 1);
    Sx.insert(pkts[i].first + t + 1);
    Sy.insert(pkts[i].second - t - 1);
    Sy.insert(pkts[i].second + t + 1);
    Sx.insert(pkts[i].first);
    Sy.insert(pkts[i].second);
  }
  int inda = 0, indb = 0;
  for (int x : Sx) {
    if (x >= 0 && x < n) {
      Skx[x] = inda;
      Rmapx[inda++] = x;
    }
  }
  for (int y : Sy) {
    if (y >= 0 && y < m) {
      Sky[y] = indb;
      Rmapy[indb++] = y;
    }
  }
  pair<int, int> A(n - 1, 0);
  pair<int, int> B(m - 1, 0);
  bool found = false;
  for (int i = 0; i < inda; ++i)
    for (int j = 0; j < indb; ++j) mapa[i][j] = -1;
  for (int l = 0; l < k; ++l) {
    int b = Skx[pkts[l].first];
    int c = Sky[pkts[l].second];
    while (b > 0 && dist(pair<int, int>(b - 1, c), l) <= t) --b;
    while (c > 0 && dist(pair<int, int>(b, c - 1), l) <= t) --c;
    while (b < inda && dist(pair<int, int>(b, c), l) <= t) {
      mapa[b][c] = l;
      ++b;
    }
  }
  for (int i = 0; i < inda; ++i) {
    int ost = 0;
    for (int j = 0; j < indb; ++j) {
      if (mapa[i][j] != -1) {
        ost = mapa[i][j];
      }
      if (dist(pair<int, int>(i, j), ost) > t) {
        A.first = min(A.first, Rmapx[i]);
        A.second = max(A.second, Rmapx[i]);
        B.first = min(B.first, Rmapy[j]);
        B.second = max(B.second, Rmapy[j]);
        found = true;
      }
    }
  }
  if (found == false) return true;
  int sx = A.second - A.first;
  int sy = B.second - B.first;
  if (max(sx, sy) <= 2 * t)
    return true;
  else
    return false;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < k; ++i) {
    scanf("%d%d", &pkts[i].first, &pkts[i].second);
    pkts[i].first--;
    pkts[i].second--;
  }
  int b = -1;
  int e = 1e9 + 100;
  while (e - b > 1) {
    int d = (b + e) / 2;
    if (query(d))
      e = d;
    else
      b = d;
  }
  printf("%d\n", e);
}
