#include <bits/stdc++.h>
using namespace std;
int a[1002][1002];
bool hh(int i, int j) {
  return ((a[i][j] + a[i + 1][j + 1] + a[i + 1][j] + a[i][j + 1]) == 4);
}
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  int i, j;
  for (int z = 0; z < k; z++) {
    cin >> i >> j;
    a[i][j] = 1;
    if (hh(i, j) == 1 || hh(i, j - 1) == 1 || hh(i - 1, j) == 1 ||
        hh(i - 1, j - 1) == 1) {
      cout << z + 1;
      return 0;
    }
  }
  cout << "0";
  return 0;
}
