#include <bits/stdc++.h>
using namespace std;
int n, m, k;
vector<int> movesi;
vector<int> movesj;
void solve(vector<vector<int> > &F) {
  for (int x = 0; x < k; x++) {
    int i = movesi[x];
    int j = movesj[x];
    F[i][j] = 0;
    for (int di = -1; di <= 0; di++)
      for (int dj = -1; dj <= 0; dj++) {
        if (!F[i + di][j + dj] && !F[i + di + 1][j + dj] &&
            !F[i + di][j + dj + 1] && !F[i + di + 1][j + dj + 1]) {
          printf("%d\n", x + 1);
          return;
        }
      }
  }
  printf("0\n");
}
int main() {
  while (cin >> n >> m >> k) {
    vector<vector<int> > F(n + 2, vector<int>(m + 2, 1));
    movesi = vector<int>(k);
    movesj = vector<int>(k);
    for (int i = 0; i < k; i++) {
      cin >> movesi[i] >> movesj[i];
    }
    solve(F);
  }
  return 0;
}
