#include <bits/stdc++.h>
using namespace std;
int a[1005][1005];
int main() {
  int n, m, k;
  cin >> n >> m >> k;
  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= m + 1; j++) {
      a[i][j] = 0;
    }
  }
  int i, j;
  bool f = true;
  int y = 1;
  while (y <= k) {
    cin >> i >> j;
    a[i][j] = 1;
    if (a[i + 1][j] == 1 && a[i][j + 1] == 1 && a[i + 1][j + 1] == 1) {
      f = false;
      break;
    }
    if (a[i - 1][j] == 1 && a[i][j + 1] == 1 && a[i - 1][j + 1] == 1) {
      f = false;
      break;
    }
    if (a[i + 1][j] == 1 && a[i][j - 1] == 1 && a[i + 1][j - 1] == 1) {
      f = false;
      break;
    }
    if (a[i][j - 1] == 1 && a[i - 1][j - 1] == 1 && a[i - 1][j] == 1) {
      f = false;
      break;
    }
    ++y;
  }
  if (f) {
    cout << 0 << "\n";
  } else {
    cout << y << "\n";
  }
  return 0;
}
