#include <bits/stdc++.h>
using namespace std;
int chess[1005][1005];
int dx[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int dy[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};
int n, m;
bool bfs(int x, int y) {
  for (int i = 0; i < 9; i++) {
    int xx = x + dx[i];
    int yy = y + dy[i];
    if (xx >= 0 && xx < n && yy >= 0 && yy < n) {
      if (chess[xx][yy] == 9) return 1;
      chess[xx][yy]++;
      if (chess[xx][yy] == 9) return 1;
    }
  }
  return 0;
}
int main() {
  memset(chess, 0, sizeof(chess));
  int i;
  int x, y;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    if (bfs(x, y)) {
      cout << i + 1 << endl;
      break;
    }
  }
  if (i == m) cout << "-1" << endl;
  return 0;
}
