#include <bits/stdc++.h>
bool a[10001][10001] = {0};
int m, n, x, y, i, count;
bool check(int x, int y) {
  if (x == 0 || y == 0)
    return false;
  else
    return a[x][y - 1] && a[x][y] && a[x][y + 1] && a[x - 1][y] &&
           a[x - 1][y - 1] && a[x - 1][y + 1] && a[x + 1][y - 1] &&
           a[x + 1][y] && a[x + 1][y + 1];
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; m--; i++) {
    scanf("%d%d", &x, &y);
    a[x][y] = true;
    if (check(x, y) || check(x, y + 1) || check(x, y - 1) || check(x + 1, y) ||
        check(x + 1, y - 1) || check(x + 1, y + 1) || check(x - 1, y) ||
        check(x - 1, y + 1) || check(x - 1, y - 1)) {
      printf("%d\n", i);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
