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