#include <bits/stdc++.h>
using namespace std;
int a[1005][1005];
int main() {
  memset(a, 0, sizeof(a));
  int n, m;
  cin >> n >> m;
  int row, col;
  int x[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
  int y[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
  for (int i = 1; i <= m; i++) {
    cin >> row >> col;
    for (int j = 0; j < 9; j++) {
      int tx = row + x[j];
      int ty = col + y[j];
      if (tx >= 1 && tx <= n && ty >= 1 && ty <= n) {
        a[tx][ty]++;
        if (a[tx][ty] == 9) {
          cout << i << endl;
          return 0;
        }
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
