#include <bits/stdc++.h>
int arr[1009][1009];
bool isSafe(int arr[1009][1009], int r, int c, int n, int m) {
  int xpos[8] = {-1, 1, 0, 0, 1, -1, -1, 1};
  int ypos[8] = {0, 0, 1, -1, 1, 1, -1, -1};
  if (r - 1 >= 1 && c - 1 >= 1 && arr[r - 1][c] == 1 &&
      arr[r - 1][c - 1] == 1 && arr[r][c - 1] == 1)
    return false;
  else if (r + 1 <= n && c - 1 >= 1 && arr[r + 1][c] == 1 &&
           arr[r][c - 1] == 1 && arr[r + 1][c - 1] == 1)
    return false;
  else if (r + 1 <= n && c + 1 <= m && arr[r + 1][c] == 1 &&
           arr[r][c + 1] == 1 && arr[r + 1][c + 1] == 1)
    return false;
  else if (r - 1 >= 1 && c + 1 <= m && arr[r - 1][c] == 1 &&
           arr[r][c + 1] == 1 && arr[r - 1][c + 1] == 1)
    return false;
  else
    return true;
}
int main() {
  int n, m, k, flag = 0;
  scanf("%d %d %d", &n, &m, &k);
  int i, j;
  memset(arr, 0, sizeof(arr));
  int r1, c1;
  for (i = 1; i <= k; i++) {
    scanf("%d %d", &r1, &c1);
    arr[r1][c1] = 1;
    if (!isSafe(arr, r1, c1, n, m)) {
      flag = 1;
      printf("%d\n", i);
      break;
    }
  }
  if (!flag) printf("0\n");
  return 0;
}
