2 5 10
2 2
1 1
1 4
2 1
1 2
1 5
2 4
2 5
1 3
2 3
 2 2 2
1 1
2 2
 3 3 9
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
 7 5 35
5 3
3 5
1 1
2 5
6 4
7 2
5 1
3 4
6 5
7 3
4 1
2 2
4 2
2 4
4 3
3 3
6 1
1 2
4 5
1 3
2 1
5 5
7 5
7 1
6 2
1 4
1 5
3 2
4 4
5 2
2 3
6 3
7 4
5 4
3 1
 1 5 4
1 1
1 2
1 4
1 5
 1 1 1
1 1
 5 7 21
4 4
4 5
5 5
5 6
5 7
5 1
5 2
4 2
3 2
3 1
3 7
3 6
2 6
1 6
1 7
1 1
1 2
1 3
1 4
2 4
3 4
 2 1 1
1 1
 2 2 4
2 1
1 1
1 2
2 2
 3000 3000 1
2222 738
 5 7 35
1 2
2 3
5 1
5 7
4 4
5 3
3 1
2 6
4 5
2 7
4 1
2 1
2 2
1 7
5 6
3 6
4 6
1 6
1 1
3 3
3 4
4 2
2 5
5 5
3 5
2 4
1 5
1 3
4 3
5 4
1 4
3 7
4 7
3 2
5 2
 5 4 1
4 1
 3 4 12
2 3
3 2
2 2
2 1
1 2
3 1
1 4
1 3
3 3
2 4
3 4
1 1
 3 3 3
1 1
2 2
3 3

8
 1
 6
 26
 4
 0
 20
 0
 2
 1
 28
 1
 9
 3

#include <bits/stdc++.h>
using namespace std;
void getInt(int &x) {
  for (x = getchar() - '0'; x < 0 || x > 9;) x = getchar() - '0';
  for (char c = getchar(); c >= '0' && c <= '9'; c = getchar())
    x = x * 10 + c - '0';
}
const int MAX_N = 3001, MAX_OP = 100001;
int pans, ans, n, m, op;
pair<int, int> o[MAX_OP];
int anc[MAX_N * MAX_N];
set<int> tbu;
bool mp[MAX_N][MAX_N];
int dy[] = {1, 1, 1, 0, 0, -1, -1, -1}, dx[] = {1, 0, -1, 1, -1, 1, 0, -1};
int Find(int x) {
  if (anc[anc[x]] == anc[x]) return anc[x];
  anc[x] = Find(anc[x]);
  return anc[x];
}
void Union(int x, int y) {
  x = Find(x);
  y = Find(y);
  anc[y] = x;
}
bool check_do(int opn) {
  int x = o[opn].first, y = o[opn].second;
  tbu.clear();
  for (int i = 0; i < 8; ++i) {
    int tx = x + dx[i], ty = y + dy[i];
    if (tx < 0 || tx >= n || !mp[tx][ty]) continue;
    if (ty == m || ty == -1) continue;
    tbu.insert(Find((tx * m + ty + 1)));
  }
  tbu.insert((x * m + y + 1));
  for (int i = 0; i < n; ++i) {
    if (!mp[i][m - 1] && !(i == x && m - 1 == y)) continue;
    for (int j = -1; j <= 1; ++j) {
      int tx = i + j;
      if (tx < 0 || tx >= n || (!mp[tx][0] && !(tx == x && 0 == y))) continue;
      if (tbu.count(Find((tx * m + 0 + 1))) &&
          tbu.count(Find((i * m + m - 1 + 1))))
        return false;
    }
  }
  for (set<int>::iterator i = tbu.begin(); i != tbu.end(); ++i) {
    Union(*tbu.begin(), *i);
  }
  mp[x][y] = true;
  return true;
}
int main() {
  getInt(n);
  getInt(m);
  getInt(op);
  for (int i = 0; i < op; ++i) {
    getInt(o[i].first);
    getInt(o[i].second);
    --o[i].first;
    --o[i].second;
  }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) anc[(i * m + j + 1)] = (i * m + j + 1);
  memset(mp, 0, sizeof mp);
  ans = 0;
  for (int i = 0; i < op; ++i) {
    if (check_do(i)) {
      pans = ans;
      ++ans;
    }
    if (pans != ans - 1) {
      cout << "sb" << ans << "  " << pans << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}
