#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, x, y, flag = 0;
  long int k;
  cin >> n >> m >> k;
  int a[n + 1][m + 1];
  for (int i = 0; i < n + 1; i++) {
    for (int j = 0; j < m + 1; j++) a[i][j] = 0;
  }
  int i, j;
  for (x = 1; x <= k; x++) {
    cin >> i >> j;
    a[i][j] = 1;
    if (a[i - 1][j - 1] == 1 && a[i - 1][j] == 1 && a[i][j - 1] == 1) {
      flag = 1;
    } else if (a[i + 1][j + 1] == 1 && a[i + 1][j] == 1 && a[i][j + 1] == 1)
      flag = 1;
    else if (a[i - 1][j + 1] == 1 && a[i - 1][j] == 1 && a[i][j + 1] == 1)
      flag = 1;
    else if (a[i + 1][j - 1] == 1 && a[i][j - 1] == 1 && a[i + 1][j] == 1)
      flag = 1;
    if (flag) break;
  }
  if (flag) {
    cout << x;
  } else
    cout << "0";
}
