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 MAXCOORD = 2 * 510 + 2;
int h, w, n;
int px[510], py[510];
bool onfire[MAXCOORD - 1][MAXCOORD - 1];
int allx[MAXCOORD], nallx;
int ally[MAXCOORD], nally;
bool allfire(int t) {
  nallx = nally = 0;
  allx[nallx++] = 0, allx[nallx++] = h;
  for (int i = 0; i < n; i++) allx[nallx++] = max(0, px[i] - t);
  for (int i = 0; i < n; i++) allx[nallx++] = min(h, px[i] + 1 + t);
  sort(allx, allx + nallx);
  nallx = unique(allx, allx + nallx) - allx;
  ally[nally++] = 0, ally[nally++] = w;
  for (int i = 0; i < n; i++) ally[nally++] = max(0, py[i] - t);
  for (int i = 0; i < n; i++) ally[nally++] = min(w, py[i] + 1 + t);
  sort(ally, ally + nally);
  nally = unique(ally, ally + nally) - ally;
  for (int x = 0; x < nallx - 1; x++)
    for (int y = 0; y < nally - 1; y++) onfire[x][y] = false;
  for (int i = 0; i < n; i++) {
    int lx = max(0, px[i] - t);
    lx = lower_bound(allx, allx + nallx, lx) - allx;
    int hx = min(h, px[i] + 1 + t);
    hx = lower_bound(allx, allx + nallx, hx) - allx;
    int ly = max(0, py[i] - t);
    ly = lower_bound(ally, ally + nally, ly) - ally;
    int hy = min(w, py[i] + 1 + t);
    hy = lower_bound(ally, ally + nally, hy) - ally;
    for (int x = (lx); x < (hx); ++x)
      for (int y = (ly); y < (hy); ++y) onfire[x][y] = true;
  }
  {
    int lx = INT_MAX, hx = INT_MIN, ly = INT_MAX, hy = INT_MIN;
    bool any = false;
    for (int x = 0; x < nallx - 1; x++)
      for (int y = 0; y < nally - 1; y++)
        if (!onfire[x][y]) {
          if (x < lx) lx = x;
          if (x > hx) hx = x;
          if (y < ly) ly = y;
          if (y > hy) hy = y;
          any = true;
        }
    if (!any) return true;
    int dx = allx[hx + 1] - allx[lx], dy = ally[hy + 1] - ally[ly];
    return dx <= 2 * t + 1 && dy <= 2 * t + 1;
  }
}
int main(int argc, char const *argv[]) {
  scanf("%d%d%d", &h, &w, &n);
  for (int i = 0; i < n; i++) scanf("%d%d", px + i, py + i), --px[i], --py[i];
  int tl = -1, r = max(h, w), mid;
  while (tl + 1 < r) {
    int mid = tl + (r - tl) / 2;
    if (allfire(mid))
      r = mid;
    else
      tl = mid;
  }
  return 0 * printf("%d\n", tl + 1);
}
