#include <bits/stdc++.h>
using namespace std;
const int MAX_BUF_SIZE = 16384;
char BUFOR[MAX_BUF_SIZE];
int BUF_SIZE, BUF_POS;
char ZZZ;
const int MXN = 1010;
const int C = 262144;
const int INF = 1000000001;
int a[MXN][MXN];
int n, m;
bool test(int sy, int sx) {
  for (int i = (-1); i <= (1); i++)
    for (int j = (-1); j <= (1); j++) {
      int ny = sy + i;
      int nx = sx + j;
      if (ny <= 0 || ny > n || nx <= 0 || nx > n) return 0;
      if (!a[ny][nx]) return 0;
    }
  return 1;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = (1); i <= (m); i++) {
    int yy, xx;
    scanf("%d %d", &xx, &yy);
    a[yy][xx] = 1;
    for (int j = (-1); j <= (1); j++)
      for (int o = (-1); o <= (1); o++) {
        int ny = yy + j;
        int nx = xx + o;
        if (test(ny, nx)) {
          printf("%d\n", i);
          return 0;
        }
      }
  }
  printf("-1\n");
  return 0;
}
