#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 507;
pair<long long, long long> p[MAXN], q[MAXN];
long long n, m, k;
long long solve_x(long long t) {
  vector<long long> vec;
  vec.push_back(1);
  for (long long i = 0; i < k; i++)
    if (p[i].first + 1 + t <= n) vec.push_back(p[i].first + t + 1);
  for (long long x : vec) {
    vector<pair<long long, long long> > temp;
    for (long long i = 0; i < k; i++) {
      if (p[i].first - t <= x && x <= p[i].first + t) {
        temp.push_back({p[i].second - t, 1});
        temp.push_back({p[i].second + t + 1, -1});
      }
    }
    long long s = 0;
    bool OK = true;
    temp.push_back({1, 0});
    sort(temp.begin(), temp.end());
    for (long long i = 0; i < temp.size(); i++) {
      pair<long long, long long> a = temp[i];
      while (temp[i].first == a.first && i < temp.size()) {
        s += temp[i].second;
        i++;
      }
      i--;
      if (s == 0 && a.first <= m) OK = false;
    }
    if (OK == false) return x;
  }
  return -1;
}
long long solve_y(long long t) {
  vector<long long> vec;
  vec.push_back(1);
  for (long long i = 0; i < k; i++)
    if (q[i].first + 1 + t <= n) vec.push_back(q[i].first + t + 1);
  for (long long x : vec) {
    vector<pair<long long, long long> > temp;
    for (long long i = 0; i < k; i++) {
      if (q[i].first - t <= x && x <= q[i].first + t) {
        temp.push_back({q[i].second - t, 1});
        temp.push_back({q[i].second + t + 1, -1});
      }
    }
    long long s = 0;
    bool OK = true;
    temp.push_back({1, 0});
    sort(temp.begin(), temp.end());
    for (long long i = 0; i < temp.size(); i++) {
      pair<long long, long long> a = temp[i];
      while (temp[i].first == a.first && i < temp.size()) {
        s += temp[i].second;
        i++;
      }
      i--;
      if (s == 0 && a.first <= n) OK = false;
    }
    if (OK == false) return x;
  }
  return -1;
}
bool check(long long t) {
  long long x = solve_x(t);
  long long y = solve_y(t);
  if (x == -1) return true;
  p[k] = {min(x + t, n), min(y + t, m)};
  q[k] = {min(y + t, m), min(x + t, n)};
  long long t1 = k;
  while (t1 && p[t1].first < p[t1 - 1].first) {
    swap(p[t1], p[t1 - 1]);
    t1--;
  }
  long long t2 = k;
  while (t2 && q[t2].first < q[t2 - 1].first) {
    swap(q[t2], q[t2 - 1]);
    t2--;
  }
  k++;
  x = solve_x(t);
  k--;
  while (t1 != k) {
    swap(p[t1], p[t1 + 1]);
    t1++;
  }
  while (t2 != k) {
    swap(q[t2], q[t2 + 1]);
    t2++;
  }
  if (x == -1)
    return true;
  else
    return false;
}
int32_t main() {
  cin >> n >> m >> k;
  for (long long i = 0; i < k; i++) {
    long long x, y;
    cin >> x >> y;
    p[i] = {x, y};
    q[i] = {y, x};
  }
  sort(p, p + k);
  sort(q, q + k);
  long long l = 0, r = 1e9 + 7;
  while (r - l > 1) {
    long long mid = ((l + r) / 2);
    if (check(mid - 1))
      r = mid;
    else
      l = mid;
  }
  cout << l << endl;
}
