#include <bits/stdc++.h>
using namespace std;
const int MOD = 10;
const double eps = 1e-5;
const int maxN = 1100;
const int inf = 1e9 + 100;
int n, m, k;
bool vis[maxN][maxN];
inline void init() {
  int a, b;
  cin >> n >> m >> k;
  for (int i = 0; i < k; i++) {
    cin >> a >> b;
    a--;
    b--;
    vis[a][b] = 1;
    bool br = false;
    if (a > 0 && b > 0 && vis[a - 1][b - 1] && vis[a - 1][b] && vis[a][b - 1])
      br = true;
    if (a < n - 1 && b > 0 && vis[a + 1][b - 1] && vis[a + 1][b] &&
        vis[a][b - 1])
      br = true;
    if (a > 0 && b < m - 1 && vis[a - 1][b + 1] && vis[a - 1][b] &&
        vis[a][b + 1])
      br = true;
    if (a < n - 1 && b < m - 1 && vis[a + 1][b + 1] && vis[a + 1][b] &&
        vis[a][b + 1])
      br = true;
    if (br) {
      cout << i + 1;
      return;
    }
  }
  cout << 0;
}
inline void solve() {}
int main() {
  ios_base::sync_with_stdio(0);
  init();
  solve();
  return 0;
}
