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;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 998244353;
const int INF = (ll)1e9 + 7;
const ll INFLL = (ll)1e18;
template <class t>
using vvector = vector<vector<t>>;
template <class t>
using vvvector = vector<vector<vector<t>>>;
template <class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template <class t, class u>
bool chmax(t &a, u b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class t, class u>
bool chmin(t &a, u b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
namespace templates {
ll modpow(ll x, ll b, ll mod = MOD) {
  ll res = 1;
  while (b) {
    if (b & 1) res = res * x % mod;
    x = x * x % mod;
    b >>= 1;
  }
  return res;
}
ll modinv(ll x) { return modpow(x, MOD - 2); }
bool was_output = false;
template <class t>
void output(t a) {
  if (was_output) cout << " ";
  cout << a;
  was_output = true;
}
void outendl() {
  was_output = false;
  cout << endl;
}
template <class t>
istream &operator>>(istream &is, vector<t> &x) {
  for (auto &i : x) is >> i;
  return is;
}
template <class t, class u>
istream &operator>>(istream &is, pair<t, u> &x) {
  is >> x.first >> x.second;
  return is;
}
template <class t>
ostream &operator<<(ostream &os, vector<t> &v) {
  os << "{";
  for (t &i : v) {
    os << i << ", ";
  }
  os << "}";
  return os;
}
template <class t = long long>
t in() {
  t res;
  cin >> res;
  return res;
}
template <class t>
void out(t x) {
  cout << x;
}
template <class t>
vector<t> sorted(
    vector<t> line,
    function<bool(t, t)> comp = [](t a, t b) { return a < b; }) {
  sort(line.begin(), line.end(), comp);
  return line;
}
template <class t>
vector<t> reversed(vector<t> line) {
  reverse(line.begin(), line.end());
  return line;
}
string reversed(string str) {
  reverse(str.begin(), str.end());
  return str;
}
long long gcd(long long a, long long b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
}  // namespace templates
using namespace templates;
int func() {
  int n = in();
  int m = in();
  int k = in();
  vector<pii> fires(k);
  for (auto &i : (fires)) {
    i.first = in() - 1;
    i.second = in() - 1;
  }
  function<bool(int time)> check =
      (function<bool(int time)>)[&](int time)->bool {
    map<int, int> zip_x;
    map<int, int> unzip_x;
    map<int, int> zip_y;
    map<int, int> unzip_y;
    function<int(int p, int upper)> insert =
        (function<int(int p, int upper)>)[&](int p, int upper)->int {
      return max(0, min(p, upper - 1));
    };
    zip_x[0] = 0;
    zip_y[0] = 0;
    zip_x[n - 1] = 0;
    zip_y[m - 1] = 0;
    for (auto &i : (fires)) {
      zip_x[insert(i.first - time, n)] = 0;
      zip_x[insert(i.first - time - 1, n)] = 0;
      zip_x[insert(i.first + time, n)] = 0;
      zip_x[insert(i.first + time + 1, n)] = 0;
      zip_y[insert(i.second - time, m)] = 0;
      zip_y[insert(i.second - time - 1, m)] = 0;
      zip_y[insert(i.second + time, m)] = 0;
      zip_y[insert(i.second + time + 1, m)] = 0;
    }
    int h;
    int w;
    {
      int cnt = 0;
      for (auto &i : (zip_x)) i.second = cnt++;
      w = cnt;
    }
    {
      int cnt = 0;
      for (auto &i : (zip_y)) i.second = cnt++;
      h = cnt;
    }
    for (auto &i : (zip_x)) unzip_x[i.second] = i.first;
    for (auto &i : (zip_y)) unzip_y[i.second] = i.first;
    vvector<bool> fired(w, vector<bool>(h, false));
    for (auto &i : (fires)) {
      vector<int> ys;
      vector<int> xs;
      {
        auto itr = zip_x.lower_bound(i.first - time);
        while (itr != zip_x.end() and itr->first <= i.first + time) {
          xs.emplace_back(itr->second);
          ++itr;
        }
      }
      {
        auto itr = zip_y.lower_bound(i.second - time);
        while (itr != zip_y.end() and itr->first <= i.second + time) {
          ys.emplace_back(itr->second);
          ++itr;
        }
      }
      for (auto &i : (ys)) {
        for (auto &j : (xs)) {
          fired[j][i] = true;
        }
      }
    }
    int min_x = INF;
    int min_y = INF;
    int max_x = 0;
    int max_y = 0;
    for (int i = (h) * (strlen("") != 0); i < (int)(strlen("") ?: (h)); ++i) {
      for (int j = (w) * (strlen("") != 0); j < (int)(strlen("") ?: (w)); ++j) {
        if (fired[j][i]) continue;
        chmax(max_x, unzip_x[j]);
        chmin(min_x, unzip_x[j]);
        chmax(max_y, unzip_y[i]);
        chmin(min_y, unzip_y[i]);
      }
    }
    return (max(max_x - min_x, max_y - min_y) + 1) / 2 <= time;
  };
  int lp = 0;
  int rp = max(n, m) + 1;
  while (lp < rp) {
    int mid = (lp + rp) / 2;
    if (check(mid)) {
      rp = mid;
    } else {
      lp = mid + 1;
    }
  }
  return lp;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << func() << endl;
  return 0;
}
