#include <bits/stdc++.h>
using namespace std;
int a[1005][1005];
bool check(int i, int j) {
  if (a[i][j] + a[i - 1][j - 1] + a[i][j - 1] + a[i - 1][j] == 4) return true;
  if (a[i][j] + a[i - 1][j] + a[i - 1][j + 1] + a[i][j + 1] == 4) return true;
  if (a[i][j] + a[i + 1][j + 1] + a[i][j + 1] + a[i + 1][j] == 4) return true;
  if (a[i][j] + a[i + 1][j] + a[i + 1][j - 1] + a[i][j - 1] == 4) return true;
  return false;
}
int main() {
  int m, n, k;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < n + 2; i++)
    for (int j = 0; j < m + 2; j++) a[i][j] = 0;
  int x, y;
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &x, &y);
    a[x][y] = 1;
    if (check(x, y)) {
      printf("%d", i + 1);
      return 0;
    }
  }
  printf("0");
  return 0;
}
