#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("O2")
const int arr = 4 * 1e5;
int x[600], y[600];
int n, m, k;
map<int, vector<pair<int, int> > > mp;
vector<pair<int, int> > remake(map<int, int> now) {
  vector<int> res1;
  int open = 0;
  for (auto i : now) {
    if (open == 0 && open + i.second != 0) res1.push_back(i.first);
    if (open != 0 && open + i.second == 0) res1.push_back(i.first - 1);
    open += i.second;
  }
  vector<pair<int, int> > res;
  for (int i = 0; i < res1.size(); i += 2)
    res.push_back({res1[i], res1[i + 1]});
  return (res);
}
bool check(int d) {
  mp.clear();
  int mx_x = 0, mx_y = 0, mn_x = 1e9 + 1, mn_y = 1e9 + 1;
  for (int i = 1; i <= k; i++) {
    mp[max(int(1), x[i] - d)].push_back({max(int(1), y[i] - d), -1});
    mp[max(int(1), x[i] - d)].push_back({min(y[i] + d + 1, n + 1), 1});
    mp[min(x[i] + d + 1, m + 1)].push_back({max(y[i] - d, 1), 1});
    mp[min(x[i] + d + 1, m + 1)].push_back({min(y[i] + d + 1, n + 1), -1});
  }
  mp[1];
  mp[m + 1];
  vector<vector<pair<int, int> > > vec;
  vector<int> pos;
  for (auto i : mp) {
    vec.push_back(i.second);
    pos.push_back(i.first);
  }
  map<int, int> now;
  for (int i = 0; i < vec.size() - 1; i++) {
    for (int j = 0; j < vec[i].size(); j++) {
      now[vec[i][j].first] -= vec[i][j].second;
    }
    vector<pair<int, int> > seg = remake(now);
    if (seg.empty()) {
      mn_x = min(mn_x, pos[i]);
      mx_x = max(mx_x, pos[i + 1] - 1);
      mx_y = n;
      mn_y = 1;
      continue;
    }
    if (seg.size() == 1 && seg[0].first == 1 && seg[0].second == n) continue;
    mn_x = min(mn_x, pos[i]);
    mx_x = max(mx_x, pos[i + 1] - 1);
    if (seg[0].first != 1) mn_y = 1;
    if (seg.size() == 1 && seg[0].first == 1) mn_y = seg[0].second + 1;
    if (seg.back().second != n) mx_y = n;
    if (seg.size() == 1 && seg.back().second == n) mx_y = seg.back().first - 1;
    for (int j = 0; j < seg.size() - 1; j++) {
      mn_y = min(mn_y, seg[j].second + 1);
      mx_y = max(mx_y, seg[j + 1].first - 1);
    }
  }
  return (max(mx_y - mn_y + 1, mx_x - mn_x + 1) <= 2 * d + 1);
}
signed main() {
  cin >> n >> m >> k;
  for (int i = 1; i <= k; i++) cin >> y[i] >> x[i];
  int l = 0;
  int r = max(n, m);
  while (r - l > 1) {
    int d = (l + r) / 2;
    if (check(d))
      r = d;
    else
      l = d;
  }
  if (check(l))
    cout << l;
  else
    cout << r;
}
