#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000000")
bool ascending(int i, int j) { return (i < j); }
bool descending(int i, int j) { return (i > j); }
using namespace std;
bool G[1000 + 10][1000 + 10];
int n, m;
bool check(int x, int y) {
  if (x <= 0 || x >= n - 1) return 0;
  if (y <= 0 || y >= n - 1) return 0;
  bool flag = true;
  if (!G[x - 1][y - 1]) flag = false;
  if (!G[x - 1][y]) flag = false;
  if (!G[x - 1][y + 1]) flag = false;
  if (!G[x][y - 1]) flag = false;
  if (!G[x][y]) flag = false;
  if (!G[x][y + 1]) flag = false;
  if (!G[x + 1][y - 1]) flag = false;
  if (!G[x + 1][y]) flag = false;
  if (!G[x + 1][y + 1]) flag = false;
  return flag;
}
int main() {
  memset((G), (0), sizeof(G));
  cin >> n >> m;
  int X[100 * 1000 + 100], Y[100 * 1000 + 100];
  for (int(i) = 0; (i) < (m); (i)++) {
    cin >> X[i] >> Y[i];
    X[i]--;
    Y[i]--;
  }
  for (int(i) = 0; (i) < (m); (i)++) {
    G[X[i]][Y[i]] = true;
    if (check(X[i] - 1, Y[i] - 1) || check(X[i] - 1, Y[i]) ||
        check(X[i] - 1, Y[i] + 1) || check(X[i], Y[i] - 1) ||
        check(X[i], Y[i]) || check(X[i], Y[i] + 1) ||
        check(X[i] + 1, Y[i] - 1) || check(X[i] + 1, Y[i]) ||
        check(X[i] + 1, Y[i] + 1)) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
