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