#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const int MAXN = 1010;
int dx1[] = {-1, 0, -1};
int dy1[] = {-1, -1, 0};
int dx2[] = {0, 1, 1};
int dy2[] = {-1, -1, 0};
int dx3[] = {-1, -1, 0};
int dy3[] = {0, 1, 1};
int dx4[] = {1, 0, 1};
int dy4[] = {0, 1, 1};
int g[MAXN][MAXN];
int main() {
  int r, c, k;
  scanf("%d%d%d", &r, &c, &k);
  for (int a = 0; a < k; ++a) {
    int rr, cc;
    scanf("%d%d", &rr, &cc);
    rr--;
    cc--;
    g[rr][cc] = 1;
    bool x = 0;
    bool ok = 1;
    for (int i = 0; i < 3; i++) {
      int nr = rr + dx1[i], nc = cc + dy1[i];
      if (nr < 0 || nc < 0 || nr >= r || nc >= c) {
        ok = 0;
        break;
      }
      if (g[nr][nc] == 0) {
        ok = 0;
      }
    }
    if (ok) x = 1;
    ok = 1;
    for (int i = 0; i < 3; i++) {
      int nr = rr + dx2[i], nc = cc + dy2[i];
      if (nr < 0 || nc < 0 || nr >= r || nc >= c) {
        ok = 0;
        break;
      }
      if (g[nr][nc] == 0) ok = 0;
    }
    if (ok) x = 1;
    ok = 1;
    for (int i = 0; i < 3; i++) {
      int nr = rr + dx3[i], nc = cc + dy3[i];
      if (nr < 0 || nc < 0 || nr >= r || nc >= c) {
        ok = 0;
        break;
      }
      if (g[nr][nc] == 0) ok = 0;
    }
    if (ok) x = 1;
    ok = 1;
    for (int i = 0; i < 3; i++) {
      int nr = rr + dx4[i], nc = cc + dy4[i];
      if (nr < 0 || nc < 0 || nr >= r || nc >= c) {
        ok = 0;
        break;
      }
      if (g[nr][nc] == 0) ok = 0;
    }
    if (ok) x = 1;
    if (x) {
      printf("%d\n", a + 1);
      return 0;
    }
  }
  printf("0\n");
  return 0;
}
