#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1005;
int n, m, res;
bool mat[MAXN][MAXN];
bool flag;
int dx[9] = {-1, 0, 1, 1, 1, 0, -1, -1, 0};
int dy[9] = {1, 1, 1, 0, -1, -1, -1, 0, 0};
void init() {
  int i, j;
  for (i = 0; i <= n; i++)
    for (j = 0; j <= n; j++) mat[i][j] = false;
}
bool safe(int x, int y) {
  if (mat[x][y] && x > 0 && y > 0 && x <= n && y <= n) return true;
  return false;
}
void judge(int x, int y) {
  int i, j;
  for (i = y - 1; i < y + 2; i++) {
    bool flg1 = true;
    for (j = 0; j < 9; j++) {
      int tx = x - 1 + dx[j];
      int ty = i + dy[j];
      if (!safe(tx, ty)) flg1 = false;
    }
    if (flg1) {
      flag = true;
      return;
    }
  }
  for (i = y - 1; i < y + 2; i++) {
    bool flg1 = true;
    for (j = 0; j < 9; j++) {
      int tx = x + dx[j];
      int ty = i + dy[j];
      if (!safe(tx, ty)) flg1 = false;
    }
    if (flg1) {
      flag = true;
      return;
    }
  }
  for (i = y - 1; i < y + 2; i++) {
    bool flg1 = true;
    for (j = 0; j < 9; j++) {
      int tx = x + 1 + dx[j];
      int ty = i + dy[j];
      if (!safe(tx, ty)) flg1 = false;
    }
    if (flg1) {
      flag = true;
      return;
    }
  }
}
void solve() {
  int i, j, k, a, b;
  res = 0;
  while (m--) {
    scanf("%d%d", &a, &b);
    mat[a][b] = true;
    if (flag) continue;
    judge(a, b);
    res++;
  }
}
int main() {
  while (scanf("%d%d", &n, &m) != EOF) {
    init();
    flag = false;
    solve();
    if (flag)
      printf("%d\n", res);
    else
      printf("-1\n");
  }
  return 0;
}
