#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
int x[512][2];
pair<int, int> X[2][512];
int S[2][2];
int R, C, N;
struct Node {
  int F, T, acc, v;
  Node* left;
  Node* right;
  Node(int F, int T, int acc, int v, Node* left, Node* right)
      : F(F), T(T), acc(acc), v(v), left(left), right(right) {}
};
int g_mid(int f, int t) { return f + (t - f) / 2; }
void insert(Node* n, int f, int t, int dif) {
  f = max(f, n->F);
  t = min(t, n->T);
  if (f >= t) return;
  if (f == n->F && t == n->T) {
    n->acc += dif;
    n->v += dif;
  } else {
    if (n->left == NULL) {
      n->left = new Node(n->F, g_mid(n->F, n->T), 0, 0, NULL, NULL);
      n->right = new Node(g_mid(n->F, n->T), n->T, 0, 0, NULL, NULL);
    }
    insert(n->left, f, t, dif);
    insert(n->right, f, t, dif);
    n->v = n->acc + min(n->left->v, n->right->v);
  }
}
bool check(int dist) {
  for (int dir = (0); dir < (2); dir++) {
    int a = 0, b = 0;
    Node* root = new Node(0, S[dir][1], 0, 0, NULL, NULL);
    while (a < N && X[dir][a].first - dist <= 1) {
      insert(root, X[dir][a].second - dist - 1, X[dir][a].second + dist, 1);
      ++a;
    }
    int mini = S[dir][0], maxi = 1;
    if (root->v == 0) mini = 1;
    while (true) {
      int prev_zero = (root->v == 0);
      int pa = ((a < N) ? X[dir][a].first - dist - 1 : S[dir][0]);
      int push_back = ((b < N) ? X[dir][b].first + dist : S[dir][0]);
      if (min(pa, push_back) == S[dir][0]) break;
      if (pa <= push_back) {
        insert(root, X[dir][a].second - dist - 1, X[dir][a].second + dist, 1);
        ++a;
      } else {
        insert(root, X[dir][b].second - dist - 1, X[dir][b].second + dist, -1);
        ++b;
      }
      if (root->v == 0) {
        mini = min(mini, min(pa, push_back) + 1);
      } else if (prev_zero) {
        maxi = max(maxi, min(pa, push_back));
      }
    }
    if (root->v == 0) maxi = S[dir][0];
    if (maxi - mini > 2 * dist) return false;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> R >> C >> N;
  for (int i = (0); i < (N); i++)
    for (int j = (0); j < (2); j++) cin >> x[i][j];
  for (int i = (0); i < (N); i++) X[0][i] = make_pair(x[i][0], x[i][1]);
  for (int i = (0); i < (N); i++) X[1][i] = make_pair(x[i][1], x[i][0]);
  sort(X[0], X[0] + N);
  sort(X[1], X[1] + N);
  S[0][0] = S[1][1] = R;
  S[1][0] = S[0][1] = C;
  int lo = 0, hi = max(R, C);
  while (lo != hi) {
    int m = lo + (hi - lo) / 2;
    if (check(m)) {
      hi = m;
    } else {
      lo = m + 1;
    }
  }
  cout << lo << endl;
  return 0;
}
