#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979323846;
const double E = 2.7182818284590452354;
static struct _ {
  ios_base::Init i;
  _() {
    cin.sync_with_stdio(0);
    cin.tie(0);
  }
} _;
inline ostream& endl(ostream& os) { return os << '\n'; }
static bool arr[1004][1004];
static inline bool test(int x, int y) {
  return arr[x - 1][y - 1] && arr[x][y - 1] && arr[x + 1][y - 1] &&
         arr[x - 1][y] && arr[x][y] && arr[x + 1][y] && arr[x - 1][y + 1] &&
         arr[x][y + 1] && arr[x + 1][y + 1];
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    x++;
    y++;
    arr[x][y] = true;
    if (test(x - 1, y - 1) || test(x, y - 1) || test(x + 1, y - 1) ||
        test(x - 1, y) || test(x, y) || test(x + 1, y) || test(x - 1, y + 1) ||
        test(x, y + 1) || test(x + 1, y + 1)) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
