#include <bits/stdc++.h>
using namespace std;
int n, m, k, mat[1010][1010], i, j, a, b, d, x, y, nr;
int sdx[] = {-1, -1, 0};
int sdy[] = {0, 1, 1};
int jdx[] = {0, 1, 1};
int jdy[] = {1, 1, 0};
int jsx[] = {1, 1, 0};
int jsy[] = {0, -1, -1};
int ssx[] = {0, -1, -1};
int ssy[] = {-1, -1, 0};
int main() {
  cin >> n >> m >> k;
  for (d = 1; d <= k; ++d) {
    cin >> a >> b;
    mat[a][b] = 1;
    nr = 0;
    for (i = 0; i < 3; ++i) {
      x = sdx[i] + a;
      y = sdy[i] + b;
      if (mat[x][y]) ++nr;
    }
    if (nr == 3) {
      cout << d;
      return 0;
    }
    nr = 0;
    for (i = 0; i < 3; ++i) {
      x = jdx[i] + a;
      y = jdy[i] + b;
      if (mat[x][y]) ++nr;
    }
    if (nr == 3) {
      cout << d;
      return 0;
    }
    nr = 0;
    for (i = 0; i < 3; ++i) {
      x = jsx[i] + a;
      y = jsy[i] + b;
      if (mat[x][y]) ++nr;
    }
    if (nr == 3) {
      cout << d;
      return 0;
    }
    nr = 0;
    for (i = 0; i < 3; ++i) {
      x = ssx[i] + a;
      y = ssy[i] + b;
      if (mat[x][y]) ++nr;
    }
    if (nr == 3) {
      cout << d;
      return 0;
    }
  }
  cout << 0;
  return 0;
}
