#include <bits/stdc++.h>
using namespace std;
bool M[1005][1005];
int n, m;
bool search_the_light(int x, int y) {
  for (int i = max(1, x - 2); i <= x; ++i)
    for (int j = max(1, y - 2); j <= y; ++j) {
      bool ok = 1;
      for (int k = i; k <= i + 2; ++k)
        for (int l = j; l <= j + 2; ++l) ok &= M[k][l];
      if (ok) return 1;
    }
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int x, y;
    cin >> x >> y;
    M[x][y] = 1;
    if (search_the_light(x, y)) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
