#include <bits/stdc++.h>
using namespace std;
int arr[1001][1001];
int main() {
  int i, j, n, m, k, a, b;
  cin >> n >> m >> k;
  for (int r = 1; r <= k; r++) {
    cin >> a >> b;
    arr[a][b] = 1;
    if ((arr[a - 1][b] && arr[a - 1][b - 1] && arr[a][b - 1]) ||
        (arr[a - 1][b] && arr[a - 1][b + 1] && arr[a][b + 1]) ||
        (arr[a + 1][b] && arr[a + 1][b - 1] && arr[a][b - 1]) ||
        (arr[a + 1][b] && arr[a + 1][b + 1] && arr[a][b + 1])) {
      cout << r << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}
