#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n, m, k, x, y;
  bool a[2000][2000];
  cin >> n >> m >> k;
  for (int i = 0; i < k; i++) {
    cin >> x >> y;
    a[x][y] = true;
    if (a[x][y] + a[x + 1][y] + a[x][y + 1] + a[x + 1][y + 1] == 4 ||
        a[x][y] + a[x - 1][y] + a[x][y + 1] + a[x - 1][y + 1] == 4 ||
        a[x][y] + a[x - 1][y] + a[x][y - 1] + a[x - 1][y - 1] == 4 ||
        a[x][y] + a[x + 1][y] + a[x][y - 1] + a[x + 1][y - 1] == 4) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}
