#include <bits/stdc++.h>
int main() {
  int a, b, c, d, e, f, g, h, i;
  int ZA[1001][1001];
  scanf("%d%d%d", &a, &b, &c);
  for (d = 0; d <= a; ++d)
    for (e = 0; e <= b; ++e) ZA[d][e] = 0;
  i = 1;
  for (d = 0; i && d < c; ++d) {
    scanf("%d%d", &e, &f);
    if (ZA[e - 1][f - 1] != 1) {
      ZA[e - 1][f - 1] = 1;
      for (g = -1; i && g < 2; g += 2)
        for (h = -1; h < 2; h += 2)
          if (ZA[e - 1 + g][f - 1 + h] == 1 && ZA[e - 1 + g][f - 1] == 1 &&
              ZA[e - 1][f - 1 + h] == 1) {
            printf("%d\n", d + 1);
            i = 0;
            break;
          }
    }
  }
  if (i) printf("0\n");
  return 0;
}
