#include <bits/stdc++.h>
using namespace std;
int dp[10001][1001], n, m;
int b[9][2] = {{-1, 0}, {1, 0},  {0, -1},  {0, 1}, {1, 1},
               {1, -1}, {-1, 1}, {-1, -1}, {0, 0}};
int find(int x, int y) {
  int i;
  if (dp[x][y] == 0) return 0;
  for (i = 0; i < 8; i++) {
    if (dp[x + b[i][0]][y + b[i][1]] == 0) return 0;
  }
  return 1;
}
int main() {
  int i, h, j;
  int a, b1;
  while (scanf("%d%d", &n, &m) != EOF) {
    memset(dp, 0, sizeof(dp));
    int ans = -1;
    for (j = 1; j <= m; j++) {
      scanf("%d%d", &a, &b1);
      dp[a][b1] = 1;
      if (ans != -1) continue;
      for (i = 0; i < 9; i++) {
        if (find(a + b[i][0], b1 + b[i][1])) {
          ans = j;
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
