#include <bits/stdc++.h>
using namespace std;
long long int cons;
long long int check(long long int a) {
  if (a >= cons || a <= -cons) a %= cons;
  return a;
}
long long int check2(long long int a) {
  if (a > 0) return a;
  long long int b = a / cons;
  a -= b * cons;
  if (a < 0) a += cons;
  return a;
}
long long int GCD(long long int a, long long int b) {
  if (b == 0) return a;
  return GCD(b, a % b);
}
long long int exp(long long int a, long long int n) {
  if (n == 0) return 1;
  if (n == 1) return check(a);
  long long int b = exp(a, n / 2);
  if (n % 2 == 0) return check(b * b);
  return check(b * check(b * a));
}
vector<pair<pair<long long int, long long int>,
            pair<long long int, long long int> > >
    p;
long long int xxx = 0, yyy = 0;
bool check(long long int xx, long long int yy, int k) {
  map<long long int, int> m;
  for (int i = 0; i < k; i++) {
    m[p[i].first.first] = 1;
    m[p[i].second.first] = 1;
    if (p[i].second.first + 1 <= xx) m[p[i].second.first + 1] = 1;
  }
  vector<long long int> temp;
  for (auto itr : m) temp.push_back(itr.first);
  vector<vector<pair<long long int, long long int> > > temp2;
  temp2.resize(temp.size());
  int first = temp.size();
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < first; j++) {
      if (temp[j] >= p[i].first.first && temp[j] <= p[i].second.first) {
        temp2[j].push_back({p[i].first.second, p[i].second.second});
      }
    }
  }
  bool flag = true;
  xxx = 1e9;
  yyy = 1e9;
  if (temp[0] != 1) {
    xxx = 1;
    yyy = 1;
    return false;
  }
  for (int j = 0; j < first; j++) {
    sort(temp2[j].begin(), temp2[j].end());
  }
  for (int i = 0; i < first; i++) {
    int len = temp2[i].size();
    if (len == 0) {
      flag = false;
      xxx = min(xxx, temp[i]);
      yyy = 1;
    }
    long long int cury = 0;
    for (auto itr : temp2[i]) {
      if (itr.first <= cury + 1)
        cury = max(cury, itr.second);
      else {
        flag = false;
        xxx = min(xxx, temp[i]);
        yyy = min(yyy, cury + 1);
      }
    }
    if (cury < yy) {
      flag = false;
      xxx = min(xxx, temp[i]);
      yyy = min(yyy, cury + 1);
    }
  }
  return flag;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cons = 1e9 + 7;
  long long int n, m, k;
  cin >> n >> m >> k;
  vector<pair<long long int, long long int> > points;
  for (int i = 0; i < k; i++) {
    long long int first, second;
    cin >> first >> second;
    points.push_back({first, second});
  }
  p.resize(k + 1);
  long long int l = 0, r = 1e9;
  long long int ans = 1e9;
  while (l <= r) {
    long long int mid = (l + r) >> 1;
    for (int i = 0; i < k; i++) {
      p[i].first.first = max((long long int)1, points[i].first - mid);
      p[i].first.second = max((long long int)1, points[i].second - mid);
      p[i].second.first = min(n, points[i].first + mid);
      p[i].second.second = min(m, points[i].second + mid);
    }
    if (check(n, m, k)) {
      ans = min(ans, mid);
      r = mid - 1;
      continue;
    }
    p[k].first.first = max((long long int)1, xxx);
    p[k].first.second = max((long long int)1, yyy);
    p[k].second.first = min(n, xxx + 2 * mid);
    p[k].second.second = min(m, yyy + 2 * mid);
    if (check(n, m, k + 1)) {
      ans = min(ans, mid);
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << ans << endl;
  return 0;
}
