#include #include using ll = long long; using ull = unsigned long long; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define REP(i, m, n) for(int i = (int)(m); i < (int)(n); i++) using namespace std; using namespace atcoder; using mint = modint998244353; const int inf = 1000000007; const ll longinf = 1ll << 60; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector a(1001, vector(1001, 0)); rep(i, n) { int x, y; cin >> x >> y; a[x][y] = 1 << i; } int all = 1 << n; vector dp(all, inf); dp[0] = 0; auto get = [&](int x, int y) { if(0 <= x && x <= 1000 && 0 <= y && y <= 1000) { return a[x][y]; } else { return 0; } }; REP(x, -2, 1003) REP(y, -2, 1003) { if(get(x, y) > 0) { continue; } vector vals; { int u = get(x + 2, y + 1) | get(x + 2, y - 1); if(u > 0) vals.push_back(u); } { int u = get(x - 2, y + 1) | get(x - 2, y - 1); if(u > 0) vals.push_back(u); } { int u = get(x + 1, y + 2) | get(x - 1, y + 2); if(u > 0) vals.push_back(u); } { int u = get(x + 1, y - 2) | get(x - 1, y - 2); if(u > 0) vals.push_back(u); } if(vals.size() > 0) { vector ndp = dp; rep(i, all) for(auto v : vals) { ndp[i | v] = min(ndp[i | v], dp[i] + 1); } dp.swap(ndp); } } if(dp[all - 1] == inf) { cout << -1 << endl; } else { cout << dp[all - 1] << endl; } return 0; }