#include <bits/stdc++.h>
using namespace ::std;
struct PP {
  pair<int, int> a, b;
} pp[510];
int d[510 * 6][510 * 6];
int n, m, k, ans;
pair<int, int> p[510];
bool check(int t) {
  vector<int> order;
  for (int i = 1; i <= k; i++) {
    pp[i].a.first = max(p[i].first - t, 1);
    pp[i].a.second = max(p[i].second - t, 1);
    pp[i].b.first = min(p[i].first + t, n);
    pp[i].b.second = min(p[i].second + t, m);
    order.push_back(pp[i].a.first);
    order.push_back(pp[i].a.second);
    order.push_back(pp[i].b.first);
    order.push_back(pp[i].b.second);
    order.push_back(pp[i].b.first + 1);
    order.push_back(pp[i].b.second + 1);
  }
  order.push_back(n);
  order.push_back(m);
  order.push_back(1);
  sort(order.begin(), order.end());
  order.erase(unique(order.begin(), order.end()), order.end());
  for (int i = 1; i <= 6 * k + 3; i++)
    for (int j = 1; j <= 6 * k + 3; j++) d[i][j] = 0;
  for (int i = 1; i <= k; i++) {
    int x1 = (int)(lower_bound(order.begin(), order.end(), pp[i].a.first) -
                   order.begin() + 1);
    int y1 = (int)(lower_bound(order.begin(), order.end(), pp[i].a.second) -
                   order.begin() + 1);
    int x2 = (int)(lower_bound(order.begin(), order.end(), pp[i].b.first) -
                   order.begin() + 1);
    int y2 = (int)(lower_bound(order.begin(), order.end(), pp[i].b.second) -
                   order.begin() + 1);
    d[x1][y1]++;
    d[x1][y2 + 1]--;
    d[x2 + 1][y1]--;
    d[x2 + 1][y2 + 1]++;
  }
  PP res = {pair<int, int>(2000000000, 2000000000), pair<int, int>(0, 0)};
  int nn =
      (int)(lower_bound(order.begin(), order.end(), n) - order.begin() + 1);
  int mm =
      (int)(lower_bound(order.begin(), order.end(), m) - order.begin() + 1);
  for (int i = 1; i <= nn; i++) {
    for (int j = 1; j <= mm; j++) {
      d[i][j] += d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1];
      if (!d[i][j]) {
        res.a.first = min(res.a.first, order[i - 1]);
        res.a.second = min(res.a.second, order[j - 1]);
        res.b.first = max(res.b.first, order[i - 1]);
        res.b.second = max(res.b.second, order[j - 1]);
      }
    }
  }
  return t >= max(res.b.first - res.a.first + 1,
                  res.b.second - res.a.second + 1) /
                  2 ||
         res.a.first == 2000000000;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= k; i++) cin >> p[i].first >> p[i].second;
  int l = 0, r = max(n, m);
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    } else
      l = mid + 1;
  }
  cout << ans << endl;
  return 0;
}
