#include <bits/stdc++.h>
int aray[1003][1003];
int main() {
  int n, m, a, b, i, j, k;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d %d", &a, &b);
    j = a - 1;
    k = b - 1;
    for (; j <= a + 1 && j <= n; j++) {
      for (k = b - 1; k <= b + 1 && k <= n; k++) {
        aray[j][k]++;
        if (aray[j][k] == 9) {
          printf("%d", i);
          return 0;
        }
      }
    }
  }
  printf("-1");
  return 0;
}
