#include <bits/stdc++.h>
using namespace std;
using pii = pair<long long, long long>;
const long long MOD = 1e9 + 7;
const long long INF = 1 << 29;
const long long N = 1e6 + 10;
const long long MOD1 = 1073741824;
struct IOsetup {
  IOsetup() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout << fixed << setprecision(20);
  }
} IO;
const long long MAX_N = 1e3 + 10;
bool g[MAX_N][MAX_N];
long long n, m;
bool check(long long r, long long c) {
  bool ok = g[r][c];
  ok &= g[r + 1][c + 1];
  ok &= g[r][c + 1];
  ok &= g[r + 1][c];
  return ok;
}
int32_t main() {
  long long k;
  cin >> n >> m >> k;
  for (long long i = 0; i < k; i++) {
    long long x, y;
    cin >> x >> y;
    g[x][y] = true;
    if (check(x, y - 1) || check(x, y) || check(x - 1, y) ||
        check(x - 1, y - 1)) {
      cout << i + 1 << endl;
      exit(0);
    }
  }
  cout << 0 << endl;
}
