#include <bits/stdc++.h>
using namespace std;
bool b[1010][1010];
int dx[] = {0, 0, 1, 1, 1, 0, -1, -1, -1},
    dy[] = {0, -1, -1, 0, 1, 1, 1, 0, -1};
int main() {
  int n, m;
  int x, y;
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) b[i][j] = false;
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    b[x][y] = true;
    for (int j = 0; j < 9; j++) {
      int tx = x + dx[j], ty = y + dy[j];
      if (tx <= 0 || ty <= 0 || n < tx || n < ty) continue;
      bool f = true;
      for (int k = 0; k < 9; k++) {
        if (tx + dx[k] <= 0 || ty + dy[k] <= 0 || n < tx + dx[k] ||
            n < ty + dy[k]) {
          f = false;
        } else {
          f &= b[tx + dx[k]][ty + dy[k]];
        }
        if (!f) break;
      }
      if (f) {
        cout << i + 1 << endl;
        return 0;
      }
    }
  }
  cout << "-1" << endl;
}
