#include <bits/stdc++.h>
using namespace std;
pair<int, int> p[12345];
long long a[1000 + 123][1000 + 123], x, n, m, ans, y, xx, yy, k;
int main() {
  cin >> n >> m >> k;
  for (int i = 0; i < k; i++) {
    cin >> x >> y;
    a[x][y] = 1;
    if (ans == 0) {
      if (a[x][y - 1] == 1 && a[x - 1][y] == 1 && a[x - 1][y - 1] == 1) ans = i;
      if (a[x][y - 1] == 1 && a[x + 1][y] == 1 && a[x + 1][y - 1] == 1) ans = i;
      if (a[x][y + 1] == 1 && a[x - 1][y] == 1 && a[x - 1][y + 1] == 1) ans = i;
      if (a[x][y + 1] == 1 && a[x + 1][y] == 1 && a[x + 1][y + 1] == 1) ans = i;
    }
  }
  if (ans == 0)
    cout << "0" << endl;
  else
    cout << ans + 1 << endl;
  return 0;
}
