#include <bits/stdc++.h>
using namespace std;
void read(int& x) { scanf("%d", &x); }
void read(long long& x) { scanf("%lld", &x); }
template <typename T, typename... Args>
void read(T& a, Args&... b) {
  read(a);
  read(b...);
}
pair<int, int> d[510];
int n, w, h;
tuple<int, int, int, int> rect[510];
bool check(int d) {
  vector<int> looks;
  for (int i = 0; i < n; ++i) {
    int first, second;
    tie(first, second) = ::d[i];
    rect[i] = make_tuple(max(1, first - d), min(w, first + d),
                         max(1, second - d), min(h, second + d));
    looks.push_back(max(1, first - d - 1));
    looks.push_back(max(1, first - d));
    looks.push_back(min(w, first + d));
    looks.push_back(min(w, first + d + 1));
  }
  looks.push_back(1);
  looks.push_back(w);
  sort((looks).begin(), (looks).end());
  looks.erase(unique((looks).begin(), (looks).end()), looks.end());
  int minx = w + 1, maxx = -1;
  int miny = h + 1, maxy = -1;
  for (int first : looks) {
    vector<pair<int, int> > gug;
    for (int i = 0; i < n; ++i) {
      int l, r, d, u;
      tie(l, r, d, u) = rect[i];
      if (first < l || r < first) continue;
      gug.emplace_back(d, u);
    }
    if (gug.empty()) {
      minx = min(minx, first);
      maxx = max(maxx, first);
      miny = 1;
      maxy = h;
      continue;
    }
    sort((gug).begin(), (gug).end());
    int min_y = 1;
    for (pair<int, int> g : gug) {
      if (g.first <= min_y && min_y <= g.second) {
        min_y = g.second + 1;
      }
    }
    int max_y = h;
    sort((gug).begin(), (gug).end(),
         [](const pair<int, int>& a, const pair<int, int>& b) {
           return a.second > b.second;
         });
    for (pair<int, int> g : gug) {
      if (g.first <= max_y && max_y <= g.second) {
        max_y = g.first - 1;
      }
    }
    if (min_y <= max_y) {
      minx = min(minx, first);
      maxx = max(maxx, first);
      miny = min(miny, min_y);
      maxy = max(maxy, max_y);
    }
  }
  return maxx - minx <= 2LL * d && maxy - miny <= 2LL * d;
}
int main() {
  read(w, h, n);
  for (int i = 0; i < n; ++i) {
    int first, second;
    read(first, second);
    d[i] = {first, second};
  }
  int l = -1, r = int(1e9) + 1;
  while (l + 1 < r) {
    int mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  printf("%d\n", r);
  return 0;
}
