#include <bits/stdc++.h>
using namespace std;
const int MAX = 503;
int n, m, k;
int xr[MAX];
int yr[MAX];
vector<int> critx;
vector<int> crity;
vector<pair<int, int> > hlp;
int tim;
bool evalx(int l) {
  if (l < 1 || l > n) {
    return false;
  }
  for (int i = 1; i <= k; i++) {
    if (abs(l - xr[i]) <= tim) {
      hlp.push_back(make_pair(max(1, yr[i] - tim), 1));
      hlp.push_back(make_pair(min(m, yr[i] + tim) + 1, 2));
    }
  }
  if (hlp.empty()) {
    return true;
  }
  sort(hlp.begin(), hlp.end());
  if (hlp[0].first > 1 || hlp[hlp.size() - 1].first < m) {
    hlp.clear();
    return true;
  }
  int sum = 0;
  for (int i = 0; i < hlp.size(); i++) {
    if (hlp[i].first > m) {
      hlp.clear();
      return false;
    }
    if (hlp[i].second == 1) {
      sum++;
    } else {
      sum--;
    }
    if (sum == 0) {
      hlp.clear();
      return true;
    }
  }
  hlp.clear();
  return false;
}
bool evaly(int l) {
  if (l < 1 || l > m) {
    return false;
  }
  for (int i = 1; i <= k; i++) {
    if (abs(l - yr[i]) <= tim) {
      hlp.push_back(make_pair(max(1, xr[i] - tim), 1));
      hlp.push_back(make_pair(min(m, xr[i] + tim) + 1, 2));
    }
  }
  if (hlp.empty()) {
    return true;
  }
  sort(hlp.begin(), hlp.end());
  if (hlp[0].first > 1 || hlp[hlp.size() - 1].first < n) {
    hlp.clear();
    return true;
  }
  int sum = 0;
  for (int i = 0; i < hlp.size(); i++) {
    if (hlp[i].first > n) {
      hlp.clear();
      return false;
    }
    if (hlp[i].second == 1) {
      sum++;
    } else {
      sum--;
    }
    if (sum == 0) {
      hlp.clear();
      return true;
    }
  }
  hlp.clear();
  return false;
}
bool check(int x) {
  tim = x;
  for (int i = 1; i <= k; i++) {
    int l = max(1, xr[i] - x);
    int r = min(n, xr[i] + x);
    critx.push_back(l);
    critx.push_back(r);
    critx.push_back(l - 1);
    critx.push_back(r + 1);
  }
  critx.push_back(1);
  critx.push_back(n);
  sort(critx.begin(), critx.end());
  std::vector<int>::iterator it;
  it = std::unique(critx.begin(), critx.end());
  critx.resize(std::distance(critx.begin(), it));
  int lft = 0, rgt = 0;
  for (int i = 0; i < critx.size(); i++) {
    if (evalx(critx[i])) {
      lft = critx[i];
      break;
    }
  }
  for (int i = critx.size() - 1; i >= 0; i--) {
    if (evalx(critx[i])) {
      rgt = critx[i];
      break;
    }
  }
  int dif = rgt - lft;
  for (int i = 1; i <= k; i++) {
    int l = max(1, yr[i] - x);
    int r = min(n, yr[i] + x);
    crity.push_back(l);
    crity.push_back(r);
    crity.push_back(l - 1);
    crity.push_back(r + 1);
  }
  crity.push_back(1);
  crity.push_back(m);
  sort(crity.begin(), crity.end());
  it = std::unique(crity.begin(), crity.end());
  crity.resize(std::distance(crity.begin(), it));
  lft = 0;
  rgt = 0;
  for (int i = 0; i < crity.size(); i++) {
    if (evaly(crity[i])) {
      lft = crity[i];
      break;
    }
  }
  for (int i = crity.size() - 1; i >= 0; i--) {
    if (evaly(crity[i])) {
      rgt = crity[i];
      break;
    }
  }
  critx.clear();
  crity.clear();
  dif = max(dif, rgt - lft);
  if (dif <= (2 * x)) {
    return true;
  } else {
    return false;
  }
}
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d %d", &xr[i], &yr[i]);
  }
  int lo = 0;
  int hi = max(n, m);
  int ans = -1;
  while (lo <= hi) {
    int mid = (lo + hi) / 2;
    if (check(mid)) {
      hi = mid - 1;
      ans = mid;
    } else {
      lo = mid + 1;
    }
  }
  printf("%d\n", ans);
  return 0;
}
