#include <bits/stdc++.h>
using namespace std;
bool MAP[1005][1005];
int main(void) {
  int n, m, k;
  int i, j;
  bool flag = 0;
  int ans = 0;
  cin >> n >> m >> k;
  for (int index = 1; index <= k; index++) {
    cin >> i >> j;
    if (!flag && ((MAP[i][j - 1] && MAP[i - 1][j - 1] && MAP[i - 1][j]) ||
                  (MAP[i][j - 1] && MAP[i + 1][j - 1] && MAP[i + 1][j]) ||
                  (MAP[i - 1][j] && MAP[i - 1][j + 1] && MAP[i][j + 1]) ||
                  (MAP[i][j + 1] && MAP[i + 1][j + 1] && MAP[i + 1][j]))) {
      ans = index;
      flag = 1;
    }
    MAP[i][j] = true;
  }
  printf("%d\n", ans);
  return 0;
}
