#include <bits/stdc++.h>
using namespace std;
struct Point {
  int x, y;
} p[100005];
int vis[1005][1005];
int n, m;
int lose(Point a) {
  if (a.x > 0 && a.y > 0) {
    if (vis[a.x - 1][a.y] && vis[a.x][a.y - 1] && vis[a.x - 1][a.y - 1])
      return 1;
  }
  if (a.x > 0 && a.y < m - 1) {
    if (vis[a.x - 1][a.y] && vis[a.x][a.y + 1] && vis[a.x - 1][a.y + 1])
      return 1;
  }
  if (a.x < n - 1 && a.y > 0) {
    if (vis[a.x + 1][a.y] && vis[a.x][a.y - 1] && vis[a.x + 1][a.y - 1])
      return 1;
  }
  if (a.x < n - 1 && a.y < m - 1) {
    if (vis[a.x + 1][a.y] && vis[a.x][a.y + 1] && vis[a.x + 1][a.y + 1])
      return 1;
  }
  return 0;
}
int main() {
  int k, i, flag, xx, yy;
  while (scanf("%d %d %d", &n, &m, &k) != EOF) {
    for (i = 0; i < k; i++) {
      scanf("%d %d", &xx, &yy);
      p[i].x = xx - 1;
      p[i].y = yy - 1;
    }
    memset(vis, 0, sizeof(vis));
    flag = 0;
    vis[p[0].x][p[0].y] = 1;
    vis[p[1].x][p[1].y] = 1;
    vis[p[2].x][p[2].y] = 1;
    for (i = 3; i < k; i++) {
      if (vis[p[i].x][p[i].y]) continue;
      vis[p[i].x][p[i].y] = 1;
      if (lose(p[i])) {
        flag = 1;
        break;
      }
    }
    if (flag)
      printf("%d\n", i + 1);
    else
      printf("0\n");
  }
  return 0;
}
