#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int arr[1010][1010];
int main() {
  int i = 1;
  int flag = 0;
  int ans = 0;
  cin >> n >> m >> k;
  for (int s = 0; s < 1000; s++)
    for (int t = 0; t < 1000; t++) arr[s][t] = 0;
  for (i = 1; i <= k && ans == 0; i++) {
    int p, q;
    cin >> p >> q;
    arr[p][q] = 1;
    if (arr[p - 1][q - 1] == 1 && arr[p][q - 1] == 1 && arr[p - 1][q] == 1) {
      flag = 1;
      ans = i;
    }
    if (arr[p][q - 1] == 1 && arr[p + 1][q - 1] == 1 && arr[p + 1][q] == 1) {
      flag = 1;
      ans = i;
    }
    if (arr[p - 1][q] == 1 && arr[p - 1][q + 1] == 1 && arr[p][q + 1] == 1) {
      flag = 1;
      ans = i;
    }
    if (arr[p + 1][q] == 1 && arr[p + 1][q + 1] == 1 && arr[p][q + 1] == 1) {
      flag = 1;
      ans = i;
    }
  }
  if (flag == 0)
    cout << 0 << endl;
  else
    cout << ans << endl;
  return 0;
}
