#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e5 + 7;
int n, m, k, a[5000][5000], x, y;
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n >> m >> k;
  for (int i = 1; i <= k; ++i) {
    cin >> x >> y;
    a[x][y] = 1;
    if (a[x - 1][y] + a[x - 1][y + 1] + a[x][y] + a[x][y + 1] == 4)
      cout << i, exit(0);
    if (a[x - 1][y - 1] + a[x - 1][y] + a[x][y - 1] + a[x][y] == 4)
      cout << i, exit(0);
    if (a[x][y - 1] + a[x][y] + a[x + 1][y - 1] + a[x + 1][y] == 4)
      cout << i, exit(0);
    if (a[x][y] + a[x + 1][y] + a[x + 1][y + 1] + a[x][y + 1] == 4)
      cout << i, exit(0);
  }
  cout << 0;
  return 0;
}
