#include <bits/stdc++.h>
using namespace std;
int n;
bool m[1005][1005];
int dir[9][8][2] = {
    {-2, -2, -2, -1, -2, 0, -1, -2, -1, -1, -1, 0, 0, -2, 0, -1},
    {-1, -2, -1, -1, -1, 0, 0, -2, 0, -1, 1, -2, 1, -1, 1, 0},
    {0, -2, 0, -1, 1, -2, 1, -1, 1, 0, 2, -2, 2, -1, 2, 0},
    {-2, -1, -2, 0, -2, 1, -1, -1, -1, 0, -1, 1, 0, -1, 0, 1},
    {-1, -1, -1, 0, -1, 1, 0, -1, 0, 1, 1, -1, 1, 0, 1, 1},
    {0, -1, 0, 1, 1, -1, 1, 0, 1, 1, 2, -1, 2, 0, 2, 1},
    {-2, 0, -2, 1, -2, 2, -1, 0, -1, 1, -1, 2, 0, 1, 0, 2},
    {-1, 0, -1, 1, -1, 2, 0, 1, 0, 2, 1, 0, 1, 1, 1, 2},
    {0, 1, 0, 2, 1, 0, 1, 1, 1, 2, 2, 0, 2, 1, 2, 2}};
bool sol(int x, int y) {
  int xc[8], yc[8];
  for (int i = 0; i < 9; i++) {
    int t = 0;
    for (int j = 0; j < 8; j++) {
      xc[j] = x + dir[i][j][0];
      yc[j] = y + dir[i][j][1];
      if (xc[j] > 0 && yc[j] > 0 && xc[j] <= n && yc[j] <= n &&
          m[xc[j]][yc[j]] == 1)
        t++;
    }
    if (t == 8) return 1;
  }
  return 0;
}
int main() {
  int k, x, y, i;
  cin >> n >> k;
  memset(m, 0, sizeof(m));
  for (i = 1; i <= k; i++) {
    cin >> x >> y;
    m[x][y] = 1;
    if (sol(x, y) && i > 8) break;
  }
  if (i <= k)
    cout << i << endl;
  else
    cout << -1 << endl;
}
