#include <bits/stdc++.h>
using namespace std;
const int maxn = int(1e5) + 123;
const int inf = 1 << 30;
const int mod = int(1e9) + 7;
bool u[1010][1010];
int n, m, k;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= k; i++) {
    int x, y;
    cin >> x >> y;
    u[x][y] = 1;
    if (u[x - 1][y] && u[x][y - 1] && u[x - 1][y - 1] ||
        u[x - 1][y] && u[x][y + 1] && u[x - 1][y + 1] ||
        u[x + 1][y] && u[x][y + 1] && u[x + 1][y + 1] ||
        u[x + 1][y] && u[x][y - 1] && u[x + 1][y - 1]) {
      cout << i;
      return 0;
    }
  }
  cout << 0;
  return 0;
}
