#include <bits/stdc++.h>
const int MAX_COORD = 1e9;
int n, m, k;
std::vector<std::pair<int, int> > centers;
void ReadInput() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < k; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    centers.emplace_back(x, y);
  }
}
int MinUncoveredCoord(std::vector<std::pair<int, int> > &pts, int n, int m,
                      int time) {
  std::sort(pts.begin(), pts.end());
  std::vector<int> critical_coords = {1};
  for (auto p : pts) {
    if (p.first + time + 1 <= n) {
      critical_coords.push_back(p.first + time + 1);
    }
  }
  std::sort(critical_coords.begin(), critical_coords.end());
  for (auto x : critical_coords) {
    std::vector<std::pair<int, int> > events;
    int cnt = 0;
    for (auto p : pts) {
      if (p.first - time <= x && x <= p.first + time) {
        if (p.second - time <= 1) {
          cnt++;
        } else {
          events.emplace_back(p.second - time, -1);
        }
        events.emplace_back(p.second + time + 1, +1);
      }
    }
    if (cnt == 0) {
      return x;
    }
    std::sort(events.begin(), events.end());
    for (auto event : events) {
      if (event.first <= m) {
        cnt -= event.second;
        if (cnt == 0) {
          return x;
        }
      }
    }
  }
  return n + 1;
}
int LightenedUp(const int time) {
  std::vector<std::pair<int, int> > pts, rev_pts;
  for (int i = 0; i < k; i++) {
    pts.push_back(centers[i]);
    rev_pts.emplace_back(centers[i].second, centers[i].first);
  }
  int x = MinUncoveredCoord(pts, n, m, time),
      y = MinUncoveredCoord(rev_pts, m, n, time);
  if (x > n) {
    return true;
  }
  x = std::min(x + time, n);
  y = std::min(y + time, m);
  pts.emplace_back(x, y);
  return MinUncoveredCoord(pts, n, m, time) > n;
}
int GetMinimalTime() {
  int left = 0, right = MAX_COORD, answer = -1;
  while (left <= right) {
    int mid = (left + right) >> 1;
    if (LightenedUp(mid)) {
      answer = mid;
      right = mid - 1;
    } else {
      left = mid + 1;
    }
  }
  return answer;
}
int main() {
  ReadInput();
  printf("%d\n", GetMinimalTime());
  return 0;
}
