#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
inline string get() {
  char ch[2000010];
  scanf("%s", ch);
  return ch;
}
const int MAX_LG = 21;
const long long maxn = 1001 + 10;
const long long base = 29;
const long long mod = 1e9 + 7;
const long long INF = 1e9 + 100;
long long ok[maxn][maxn];
long long dx[] = {0, 0, -1, 1};
long long dy[] = {1, -1, 0, 0};
int32_t main() {
  long long n = in(), q = in();
  for (long long _ = 0; _ < q; _++) {
    long long a = in() + 1, b = in() + 1;
    ok[a][b] = true;
    for (long long x = a - 2; x <= a; x++) {
      for (long long y = b - 2; y <= b; y++) {
        long long tot = 0;
        for (long long pt = x; pt <= x + 2; pt++) {
          for (long long pt2 = y; pt2 <= y + 2; pt2++) {
            tot += ok[pt][pt2];
          }
        }
        if (tot == 9) return cout << _ + 1 << "\n", 0;
      }
    }
  }
  cout << -1 << "\n";
}
