#include <bits/stdc++.h>
using namespace std;
long long int n, a[3000][3000], v[3000], j;
int main() {
  long long int l, max, min, r, k, i, flag = 0, ans = 0, temp = 0, pos = 0,
                                      neg = 0, cnt = 0, d = 0, size, m;
  cin >> n >> m >> d;
  for (i = 0; i < d; i++) {
    cin >> l >> k;
    a[l][k] = 1;
    if (a[l - 1][k] == 1 && a[l][k - 1] == 1 && a[l - 1][k - 1] == 1) {
      cout << i + 1;
      return 0;
    }
    if (a[l][k + 1] == 1 && a[l - 1][k] == 1 && a[l - 1][k + 1] == 1) {
      cout << i + 1;
      return 0;
    }
    if (a[l][k - 1] == 1 && a[l + 1][k] == 1 && a[l + 1][k - 1] == 1) {
      cout << i + 1;
      return 0;
    }
    if (a[l + 1][k] == 1 && a[l][k + 1] == 1 && a[l + 1][k + 1] == 1) {
      cout << i + 1;
      return 0;
    }
  }
  cout << 0;
  return 0;
}
