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