#include <bits/stdc++.h>
using namespace std;
int dir[8][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1},
                 {0, 1},   {1, -1}, {1, 0},  {1, 1}};
int n, m, k, res, x, y, tx, ty;
int mat[1010][1010], mark[8];
int main() {
  memset(mat, 0, sizeof mat);
  res = 0;
  cin >> n >> m >> k;
  for (int i = 1; i <= k; ++i) {
    cin >> x >> y;
    mat[x][y] = 1;
    if (res) continue;
    memset(mark, 0, sizeof mark);
    for (int j = 0; j < 8; ++j) {
      tx = x + dir[j][0];
      ty = y + dir[j][1];
      if (mat[tx][ty]) {
        mark[j] = 1;
      }
    }
    if ((mark[0] && mark[1] && mark[3]) || (mark[1] && mark[2] && mark[4]) ||
        (mark[3] && mark[5] && mark[6]) || (mark[4] && mark[6] && mark[7]))
      res = i;
  }
  cout << res << endl;
  return 0;
}
