#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500000;
const int SUPERN = 5000000;
const int MAXS = 325;
const int SUPERS = 1000;
const int MD = 1e9 + 7;
int n, m, k, l, r, md, x, y;
pair<int, int> p[600], q[600];
long long sum(long long a, long long b) { return (a + b) % MD; }
long long mu(long long a, long long b) { return (a * b) % MD; }
long long mn(long long a, long long b) { return (a - b + MD) % MD; }
int slx() {
  vector<int> can;
  can.push_back(1);
  for (int i = 0; i < k; ++i) {
    if (p[i].first + 1 + md <= n) can.push_back(p[i].first + md + 1);
  }
  for (auto u : can) {
    vector<pair<int, int> > sl;
    for (int i = 0; i < k; ++i) {
      if (p[i].first - md <= u && u <= p[i].first + md) {
        int e = p[i].second - md;
        int h = p[i].second + md + 1;
        sl.push_back({e, 1});
        sl.push_back({h, -1});
      }
    }
    int s = 0;
    bool f = true;
    sl.push_back({1, 0});
    sort(sl.begin(), sl.end());
    for (int i = 0; i < sl.size(); ++i) {
      pair<int, int> v = sl[i];
      while (sl[i].first == v.first && i < sl.size()) {
        s += sl[i].second, i++;
      }
      i--;
      if (s == 0 && v.first <= m) f = false;
    }
    if (!f) return u;
  }
  return -1;
}
int sly() {
  vector<int> can;
  can.push_back(1);
  for (int i = 0; i < k; ++i) {
    if (q[i].first + 1 + md <= n) can.push_back(q[i].first + md + 1);
  }
  for (auto u : can) {
    vector<pair<int, int> > sl;
    for (int i = 0; i < k; ++i) {
      if (q[i].first - md <= u && u <= q[i].first + md) {
        sl.push_back({q[i].second - md, 1});
        sl.push_back({q[i].second + md + 1, -1});
      }
    }
    int s = 0;
    bool f = true;
    sl.push_back({1, 0});
    sort(sl.begin(), sl.end());
    for (int i = 0; i < sl.size(); ++i) {
      auto v = sl[i];
      while (sl[i].first == v.first && i < sl.size()) {
        s += sl[i].second, i++;
      }
      i--;
      if (s == 0 && v.first <= n) f = false;
    }
    if (!f) return u;
  }
  return -1;
}
bool chk() {
  x = slx();
  y = sly();
  if (x == -1) return true;
  p[k] = {min(x + md, n), min(y + md, m)};
  q[k] = {min(y + md, m), min(x + md, n)};
  int cnt = k;
  while (cnt && p[cnt].first < p[cnt - 1].first) {
    swap(p[cnt], p[cnt - 1]);
    cnt--;
  }
  int cnt3 = k;
  while (cnt3 && q[cnt3].first < q[cnt3 - 1].first) {
    swap(q[cnt3], q[cnt3 - 1]);
    cnt3--;
  }
  k++;
  x = slx();
  k--;
  while (cnt != k) swap(p[cnt], p[cnt + 1]), cnt++;
  while (cnt3 != k) swap(q[cnt3], q[cnt3 + 1]), cnt3++;
  if (x == -1) return true;
  return false;
}
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < k; ++i) {
    cin >> x >> y;
    p[i] = {x, y};
    q[i] = {y, x};
  }
  sort(p, p + k);
  sort(q, q + k);
  l = 0;
  r = 1e9;
  while (r - l - 1) {
    md = (l + r) >> 1;
    md--;
    if (chk()) {
      r = md + 1;
    } else
      l = md + 1;
  }
  cout << l;
  return 0;
}
