#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 5;
int a[MAXN][MAXN];
int n, m, k;
bool check(int x, int y) {
  if (x < 1 || x > n || y < 1 || y > m) return false;
  for (int i = x; i <= x + 1; i++)
    for (int j = y; j <= y + 1; j++) {
      if (i > n || j > m) return false;
      if (a[i][j] == 0) return false;
    }
  return true;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> k;
  if (n < 2 || m < 2) {
    cout << "0" << endl;
    return 0;
  }
  int x, y;
  for (int i = 0; i < k; i++) {
    cin >> x >> y;
    a[x][y] = 1;
    if (check(x - 1, y - 1) || check(x - 1, y) || check(x, y - 1) ||
        check(x, y)) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << "0" << endl;
  return 0;
}
