#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
const int maxn = 1000 + 10;
const int mod = 1e9;
int n, m, k, x, y, mark[maxn][maxn];
int main() {
  int flag = 1, ans;
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d %d", &x, &y);
    mark[x][y] = 1;
    if (mark[x][y] && mark[x + 1][y] && mark[x][y + 1] && mark[x + 1][y + 1] &&
        flag == 1) {
      ans = i;
      flag = 0;
    }
    if (x - 1 > 0 && y - 1 > 0 && mark[x][y] && mark[x - 1][y] &&
        mark[x][y - 1] && mark[x - 1][y - 1] && flag == 1) {
      ans = i;
      flag = 0;
    }
    if (y - 1 > 0 && mark[x][y] && mark[x + 1][y] && mark[x][y - 1] &&
        mark[x + 1][y - 1] && flag == 1) {
      ans = i;
      flag = 0;
    }
    if (x - 1 > 0 && mark[x][y] && mark[x][y + 1] && mark[x - 1][y] &&
        mark[x - 1][y + 1] && flag == 1) {
      ans = i;
      flag = 0;
    }
  }
  if (flag)
    printf("0\n");
  else
    printf("%d\n", ans);
  return 0;
}
