#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k, s, r, i, ans = 1e8;
  char a[1011][1011];
  memset(a, 0, sizeof(a));
  scanf("%d %d %d", &n, &m, &k);
  for (i = 1; i <= k; i++) {
    scanf("%d %d", &r, &s);
    a[r][s] = 1;
    if (a[r - 1][s - 1] == 1 && a[r - 1][s] == 1 && a[r][s - 1] == 1 &&
        a[r][s] == 1)
      ans = min(ans, i);
    if (a[r - 1][s + 1] == 1 && a[r - 1][s] == 1 && a[r][s + 1] == 1 &&
        a[r][s] == 1)
      ans = min(ans, i);
    if (a[r + 1][s - 1] == 1 && a[r + 1][s] == 1 && a[r][s - 1] == 1 &&
        a[r][s] == 1)
      ans = min(ans, i);
    if (a[r + 1][s + 1] == 1 && a[r + 1][s] == 1 && a[r][s + 1] == 1 &&
        a[r][s] == 1)
      ans = min(ans, i);
  }
  if (ans == 1e8) ans = 0;
  printf("%d\n", ans);
  return 0;
}
