#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, k, l, r;
  bool a[1100][1100];
  memset(a, 0, sizeof(a));
  cin >> n >> m >> k;
  int s = 0;
  for (int i = 0; i < k; i++) {
    cin >> l >> r;
    if (s == 0) {
      l = l + 4;
      r = r + 4;
      a[l][r] = 1;
      if ((a[l + 1][r] == 1 && a[l][r + 1] == 1 && a[l + 1][r + 1] == 1) ||
          (a[l - 1][r] == 1 && a[l][r + 1] == 1 && a[l - 1][r + 1] == 1) ||
          (a[l - 1][r] == 1 && a[l][r - 1] == 1 && a[l - 1][r - 1] == 1) ||
          (a[l + 1][r] == 1 && a[l][r - 1] == 1 && a[l + 1][r - 1] == 1)) {
        s = i + 1;
      }
    }
  }
  cout << s;
  return 0;
}
