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;
const int inf = 2 * 1e9;
int TLeft, TRight;
struct node_t;
typedef node_t* node;
struct node_t {
  int mini, add;
  node l, r;
  node_t(int a = 0) : mini(a), add(0), l(NULL), r(NULL) {}
};
int get_mini(node v) { return v ? v->mini : 0; }
int get_add(node v) { return v ? v->add : 0; }
void add(node v, int tl, int tr, int l, int r, int c = 1) {
  if (l > r) return;
  if (tl == l && tr == r) {
    v->add += c;
    v->mini += c;
    return;
  }
  int tm = (tl + tr) / 2;
  if (!v->l) v->l = new node_t();
  if (!v->r) v->r = new node_t();
  add(v->l, tl, tm, l, min(tm, r), c);
  add(v->r, tm + 1, tr, max(tm + 1, l), r, c);
  v->mini = min(v->l->mini, v->r->mini) + v->add;
}
int FindFirstZero(node v, int tl, int tr) {
  if (v->mini != 0) return -1;
  int tm = (tl + tr) / 2;
  if (!v->l)
    return tl;
  else {
    if (v->l->mini == 0) return FindFirstZero(v->l, tl, tm);
  }
  if (!v->r)
    return tm + 1;
  else {
    return FindFirstZero(v->r, tm + 1, tr);
  }
}
node CreateTree(int l, int r) {
  TLeft = l, TRight = r;
  return new node_t();
}
void plus1(node v, int l, int r) { add(v, TLeft, TRight, l, r, 1); }
void minus1(node v, int l, int r) { add(v, TLeft, TRight, l, r, -1); }
struct item {
  int main_coord;
  int minor_l, minor_r;
  int type;
  item(int a, int b, int c, int d)
      : main_coord(a), minor_l(b), minor_r(c), type(d) {}
};
bool compare(item a, item b) {
  if (a.main_coord != b.main_coord)
    return a.main_coord < b.main_coord;
  else
    return a.type < b.type;
}
int n, m, k;
vector<pair<int, int> > input;
int find_min_x_coord(int t) {
  node root = CreateTree(0, m - 1);
  vector<item> scanline;
  for (int i = 0; i < input.size(); i++) {
    scanline.push_back(item(max(-1, input.at(i).first - t - 1),
                            max(0, input.at(i).second - t),
                            min(m - 1, input.at(i).second + t), -1));
    scanline.push_back(item(min(n, input.at(i).first + t + 1),
                            max(0, input.at(i).second - t),
                            min(m - 1, input.at(i).second + t), 1));
  }
  sort(scanline.begin(), scanline.end(), compare);
  int j = 0;
  while (scanline.at(j).main_coord == -1 && scanline.at(j).type == -1) {
    int l_ = scanline.at(j).minor_l;
    int r_ = scanline.at(j).minor_r;
    plus1(root, l_, r_);
    j++;
  }
  if (FindFirstZero(root, TLeft, TRight) != -1) return 0;
  for (int i = j; i < scanline.size(); i++) {
    int l_ = scanline.at(i).minor_l;
    int r_ = scanline.at(i).minor_r;
    if (scanline.at(i).type == -1)
      plus1(root, l_, r_);
    else
      minus1(root, l_, r_);
    if (FindFirstZero(root, TLeft, TRight) != -1) {
      if (scanline.at(i).main_coord != n)
        return scanline.at(i).main_coord;
      else
        return -1;
    }
  }
  return -1;
}
int find_min_y_coord(int t) {
  node root = CreateTree(0, n - 1);
  vector<item> scanline;
  for (int i = 0; i < input.size(); i++) {
    scanline.push_back(item(max(-1, input.at(i).second - t - 1),
                            max(0, input.at(i).first - t),
                            min(n - 1, input.at(i).first + t), -1));
    scanline.push_back(item(min(m, input.at(i).second + t + 1),
                            max(0, input.at(i).first - t),
                            min(n - 1, input.at(i).first + t), 1));
  }
  sort(scanline.begin(), scanline.end(), compare);
  int j = 0;
  while (scanline.at(j).main_coord == -1 && scanline.at(j).type == -1) {
    int l_ = scanline.at(j).minor_l;
    int r_ = scanline.at(j).minor_r;
    plus1(root, l_, r_);
    j++;
  }
  if (FindFirstZero(root, TLeft, TRight) != -1) return 0;
  for (int i = j; i < scanline.size(); i++) {
    int l_ = scanline.at(i).minor_l;
    int r_ = scanline.at(i).minor_r;
    if (scanline.at(i).type == -1)
      plus1(root, l_, r_);
    else
      minus1(root, l_, r_);
    if (FindFirstZero(root, TLeft, TRight) != -1) {
      if (scanline.at(i).main_coord != m)
        return scanline.at(i).main_coord;
      else
        return -1;
    }
  }
  return -1;
}
bool check(int t) {
  int x0 = find_min_x_coord(t);
  int y0 = find_min_y_coord(t);
  if (x0 == -1) return 1;
  int put_x, put_y;
  put_x = min(x0 + t, n - 1);
  put_y = min(y0 + t, m - 1);
  input.push_back(make_pair(put_x, put_y));
  x0 = find_min_x_coord(t);
  y0 = find_min_y_coord(t);
  input.pop_back();
  if (x0 == -1)
    return 1;
  else
    return 0;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  int a, b;
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &a, &b);
    a--;
    b--;
    input.push_back(make_pair(a, b));
  }
  int l = 0, r = max(n, m);
  while (r - l > 1) {
    int m = (l + r) / 2;
    if (check(m))
      r = m;
    else
      l = m + 1;
  }
  if (check(l))
    printf("%d", l);
  else
    printf("%d", r);
  return 0;
}
