#include <bits/stdc++.h>
using namespace std;
#define int long long
bool works(int n, int m, vector<vector<int>> &carpet, int s) {
vector<vector<int>> ps(n+1, vector<int>(m+1)), clean(n+2, vector<int>(m+2));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
ps[i][j] = ps[i-1][j] + ps[i][j-1] - ps[i-1][j-1] + carpet[i][j];
}
}
for (int i = 1; i <= n-s+1; i++) {
for (int j = 1; j <= m-s+1; j++) {
if (ps[i+s-1][j+s-1]-ps[i+s-1][j-1]-ps[i-1][j+s-1]+ps[i-1][j-1] == 0) {
clean[i][j]++; clean[i+s][j]--; clean[i][j+s]--; clean[i+s][j+s]++;
}
}
}
vector<vector<int>> cps(n+1, vector<int>(m+1));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cps[i][j] = cps[i-1][j] + cps[i][j-1] - cps[i-1][j-1] + clean[i][j];
if (!carpet[i][j] && cps[i][j] == 0) return false;
}
}
return true;
}
int main() {
// input
int n, m, k; cin >> n >> m >> k;
vector<vector<int>> carpet(n+1, vector<int>(m+1));
for (int i = 0; i < k; i++) {
int x, y; cin >> x >> y;
carpet[x][y] = true;
}
// binary search
int l = 1, r = min(n, m);
while (l < r) {
int s = (l+r+1)/2;
if (works(n, m, carpet, s)) {
l = s;
} else {
r = s-1;
}
}
cout << l << endl;
}