#include <bits/stdc++.h>
using namespace std;
int a[1010][1010], r, c;
bool check(int i, int j) {
  if (i < 0 || j < 0 || i + 1 >= r || j + 1 >= c) return 0;
  return a[i][j] && a[i + 1][j] && a[i][j + 1] && a[i + 1][j + 1];
}
int main() {
  int q, i, j;
  scanf("%d%d%d", &r, &c, &q);
  for (int k = 1; k <= q; k++) {
    scanf("%d%d", &i, &j);
    i--;
    j--;
    a[i][j] = 1;
    if (check(i - 1, j - 1) || check(i - 1, j) || check(i, j - 1) ||
        check(i, j)) {
      printf("%d\n", k);
      return 0;
    }
  }
  printf("0\n");
  return 0;
}
