#include <bits/stdc++.h>
using namespace std;
bool v[1000][1000];
int dr[] = {0, -1, -1, 0, 1, 1, 1, 0, -1};
int dc[] = {0, 0, 1, 1, 1, 0, -1, -1, -1};
long long n, m, s = 0, x, y;
bool c(int a, int b) {
  for (int i = 0; i < 9; i++) {
    int cr = a + dr[i];
    int cc = b + dc[i];
    if (cr >= n || cr <= -1 || cc >= n || cc <= -1) continue;
    s = 0;
    for (int j = 0; j < 9; j++) {
      int nr = cr + dr[j];
      int nc = cc + dc[j];
      if (nr >= n || nr <= -1 || nc >= n || nc <= -1) continue;
      if (v[nr][nc] == 1) s++;
    }
    if (s == 9) return true;
  }
  return false;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    v[x - 1][y - 1] = 1;
    if (c(x - 1, y - 1)) {
      cout << i + 1;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
