The capital of Berland looks like a rectangle of size n × m of the square blocks of same size.

Fire!

It is known that k + 1 blocks got caught on fire (k + 1 ≤ n·m). Those blocks are centers of ignition. Moreover positions of k of these centers are known and one of these stays unknown. All k + 1 positions are distinct.

The fire goes the following way: during the zero minute of fire only these k + 1 centers of ignition are burning. Every next minute the fire goes to all neighbouring blocks to the one which is burning. You can consider blocks to burn for so long that this time exceeds the time taken in the problem. The neighbouring blocks are those that touch the current block by a side or by a corner.

Berland Fire Deparment wants to estimate the minimal time it takes the fire to lighten up the whole city. Remember that the positions of k blocks (centers of ignition) are known and (k + 1)-th can be positioned in any other block.

Help Berland Fire Department to estimate the minimal time it takes the fire to lighten up the whole city.

Input

The first line contains three integers n, m and k (1 ≤ n, m ≤ 109, 1 ≤ k ≤ 500).

Each of the next k lines contain two integers xi and yi (1 ≤ xi ≤ n, 1 ≤ yi ≤ m) — coordinates of the i-th center of ignition. It is guaranteed that the locations of all centers of ignition are distinct.

Output

Print the minimal time it takes the fire to lighten up the whole city (in minutes).

Examples

Input

7 7 3
1 2
2 1
5 5


Output

3


Input

10 5 1
3 3


Output

2

Note

In the first example the last block can have coordinates (4, 4).

In the second example the last block can have coordinates (8, 3).
#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c *x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  ~debug() { cerr << endl; }
  template <class c>
  typename enable_if<sizeof dud<c>(0) != 1, debug &>::type operator<<(c i) {
    cerr << boolalpha << i;
    return *this;
  }
  template <class c>
  typename enable_if<sizeof dud<c>(0) == 1, debug &>::type operator<<(c i) {
    return *this << range(begin(i), end(i));
  }
  template <class c, class b>
  debug &operator<<(pair<b, c> d) {
    return *this << "(" << d.first << ", " << d.second << ")";
  }
  template <class c>
  debug &operator<<(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it;
    return *this << "]";
  }
};
long double eps = (long double)1 / 1e6;
const long double pi = 3.14159265359;
long long inf = 1e18, mod1 = 1e9 + 7;
long long sqr(long long a) { return a * a; }
long long qb(long long a) { return a * a * a; }
void umin(int &a, int b) { a = min(a, b); }
void umax(int &a, int b) { a = max(a, b); }
bool is_prime(long long val) {
  for (long long i = 2; i <= sqrt(val); i++)
    if (val % i == 0) return 0;
  return 1;
}
long long gcd(long long a, long long b) { return !a ? b : gcd(b % a, a); }
long long binpow(long long a, long long b, long long mod) {
  return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod
                    : sqr(binpow(a, b / 2, mod)) % mod)
           : 1;
}
long long binmult(long long a, long long b, long long mod) {
  return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod
                    : (2 * binmult(a, b / 2, mod)) % mod)
           : 0;
}
const long long tx[4] = {0, 1, -1, 1};
const long long ty[4] = {-1, 0, 1, 1};
const char rev_to[4] = {'E', 'W', 'N', 'S'};
const int M = 1e9;
const int N = 2e5 + 2;
const int ppp = 73;
const int lg = 19;
const int OPEN = 1;
const int CLOSE = 0;
auto rnd = bind(uniform_int_distribution<long long>(1, N), mt19937(time(0)));
void bad() {
  cout << "NE";
  exit(0);
}
int n, m, k;
pair<int, int> a[N];
struct kvadr {
  int x1, y1, x2, y2;
  kvadr(int x, int y, int k)
      : x1(max(1, x - k)),
        x2(min(n, x + k)),
        y1(max(1, y - k)),
        y2(min(m, y + k)) {}
};
struct stuff {
  int x, type, ind;
  stuff(int _l, int _tp, int _ind) : type(_tp), x(_l), ind(_ind) {}
  const bool operator<(const stuff &other) const {
    return (x == other.x
                ? (type == other.type ? ind < other.ind : type > other.type)
                : x < other.x);
  }
};
bool ok(int mid) {
  map<int, vector<pair<int, int>>> mp;
  vector<kvadr> second;
  for (int i = 0; i < k; i++) {
    second.emplace_back(kvadr(a[i].first, a[i].second, mid));
    mp[second[i].x1].push_back({i, OPEN});
    mp[second[i].x2 + 1].push_back({i, CLOSE});
    if ((int)mp[second[i].x1 - 1].size()) {
    }
    if ((int)mp[second[i].x1 + 1].size()) {
    }
    if ((int)mp[second[i].x2 - 1].size()) {
    }
    if ((int)mp[second[i].x2 + 1].size()) {
    }
  }
  if ((int)mp[1].size()) {
  }
  if ((int)mp[n].size()) {
  }
  set<stuff> cur;
  set<int> lel;
  set<int> lsty, lstx;
  for (auto &z : mp) {
    if (z.first > n || z.first <= 0) continue;
    for (auto &g : z.second) {
      if (g.second == OPEN)
        lel.insert(g.first);
      else
        lel.erase(g.first);
    }
    for (auto &g : lel) {
      cur.insert(stuff(second[g].y1, OPEN, g));
      cur.insert(stuff(second[g].y2 + 1, CLOSE, g));
    }
    cur.insert(stuff(1, CLOSE, -1));
    cur.insert(stuff(m, CLOSE, -1));
    int kl = 0;
    bool psd = 0;
    for (auto &g : cur) {
      if (g.type == CLOSE && g.ind != -1) kl--;
      if (g.type == OPEN) kl++;
      if (!kl && g.x <= m) lsty.insert(g.x), psd = 1;
    }
    cur.clear();
    if (psd) lstx.insert(z.first);
  }
  int first = ((int)lsty.size() ? (*lsty.rbegin() - *lsty.begin()) : 0),
      ss = ((int)lstx.size() ? (*lstx.rbegin() - *lstx.begin()) : 0);
  bool ok =
      (ceil((long double)first / 2) <= mid && ceil((long double)ss / 2) <= mid);
  return ok;
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  ;
  cin >> n >> m >> k;
  for (int i = 0; i < k; i++) cin >> a[i].first >> a[i].second;
  int l = 0, r = 1e9 + 1;
  while (l != r) {
    int tm = (l + r) >> 1;
    if (ok(tm))
      r = tm;
    else
      l = tm + 1;
  }
  cout << l;
  return 0;
}
