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