#include <bits/stdc++.h>
using namespace std;
int x[505], y[505];
bool canDoit(int w, int n, int m, int k) {
  vector<pair<int, pair<int, pair<int, int> > > > tmp;
  tmp.push_back({1, {0, {0, 0}}});
  tmp.push_back({1, {1, {0, 0}}});
  tmp.push_back({n, {0, {0, 0}}});
  tmp.push_back({n, {1, {0, 0}}});
  for (int i = 1; i <= k; ++i) {
    int minY = max(1, y[i] - w);
    int maxY = min(m, y[i] + w);
    int minX = max(1, x[i] - w);
    int maxX = min(n, x[i] + w);
    tmp.push_back({minX, {0, {minY, maxY}}});
    tmp.push_back({maxX, {1, {minY, maxY}}});
  }
  sort(tmp.begin(), tmp.end());
  multiset<pair<int, int> > v;
  int minX = n + 1, maxX = 0, minY = m + 1, maxY = 0;
  v.insert({m + 1, 0});
  int prevX = 0;
  for (int i = 0, j; i < tmp.size(); i = j) {
    int cur = tmp[i].first;
    if (i != 0 && prevX + 1 < cur) {
      int pos = 0;
      for (pair<int, int> x : v) {
        if (pos + 1 < x.first) {
          minY = min(minY, pos + 1);
          maxY = max(maxY, x.first - 1);
          minX = min(minX, prevX + 1);
          maxX = max(maxX, cur - 1);
        }
        pos = max(pos, x.second);
      }
    }
    for (j = i; j < tmp.size(); ++j) {
      if (tmp[j].first == cur && tmp[j].second.first == 0) {
        v.insert(tmp[j].second.second);
      } else {
        break;
      }
    }
    int pos = 0;
    for (pair<int, int> x : v) {
      if (pos + 1 < x.first) {
        minY = min(minY, pos + 1);
        maxY = max(maxY, x.first - 1);
        minX = min(minX, prevX + 1);
        maxX = cur;
      }
      pos = max(pos, x.second);
    }
    for (; j < tmp.size(); ++j) {
      if (tmp[j].first == cur && tmp[j].second.first == 1) {
        auto it = v.find(tmp[j].second.second);
        v.erase(it);
      } else {
        break;
      }
    }
    prevX = cur;
  }
  int width = w * 2 + 1;
  if (maxX - minX + 1 > width || maxY - minY + 1 > width) {
    return false;
  } else {
    return true;
  }
}
void solve() {
  int n, m, k;
  scanf("%d %d %d ", &n, &m, &k);
  for (int i = 1; i <= k; ++i) {
    scanf("%d %d ", &x[i], &y[i]);
  }
  int l = 0, r = 1e9, mid;
  while (l < r) {
    mid = (l + r) / 2;
    if (canDoit(mid, n, m, k)) {
      r = mid;
    } else {
      l = mid + 1;
    }
  }
  printf("%d\n", l);
}
int main() {
  solve();
  return 0;
}
