#include <bits/stdc++.h>
using namespace std;
long long vis[1003][1003];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  long long mn = INT_MAX;
  for (long long i = 1; i <= m; i++) {
    long long x, y;
    cin >> x >> y;
    x += 1, y += 1;
    for (long long j = x - 1; j <= x + 1; j++) {
      for (long long k = y - 1; k <= y + 1; k++) {
        vis[j][k] += 1;
        if (vis[j][k] == 9) mn = min(mn, i);
      }
    }
  }
  if (mn == INT_MAX)
    cout << "-1"
         << "\n";
  else
    cout << mn << "\n";
}
