#include <bits/stdc++.h>
using namespace std;
bool flag[1005][1005];
int way[9][2] = {{1, 0},  {-1, 0}, {0, 1},   {0, -1}, {1, 1},
                 {1, -1}, {-1, 1}, {-1, -1}, {0, 0}};
bool check(int x, int y) {
  if (flag[x][y] == false) return false;
  for (int i = 0; i < 8; i++)
    if (flag[x + way[i][0]][y + way[i][1]] == false) return false;
  return true;
}
int main() {
  int n, m;
  while (scanf("%d%d", &n, &m) != EOF) {
    memset(flag, false, sizeof(flag));
    int x, y;
    int ans = -1;
    for (int t = 1; t <= m; t++) {
      scanf("%d%d", &x, &y);
      flag[x][y] = true;
      int i;
      if (ans != -1) continue;
      for (i = 0; i < 9; i++) {
        if (check(x + way[i][0], y + way[i][1])) {
          ans = t;
          break;
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
