#include #include #define rep(i,n) for(int i=0;i vi; typedef vector vl; typedef vector> vvi; typedef vector> vvl; typedef long double ld; typedef pair P; ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;} template ostream& operator<<(ostream& os, const static_modint& a) {os << a.val(); return os;} template ostream& operator<<(ostream& os, const dynamic_modint& a) {os << a.val(); return os;} template istream& operator>>(istream& is, vector& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template ostream& operator<<(ostream& os, const pair& p){os << p.first << ' ' << p.second; return os;} template ostream& operator<<(ostream& os, const vector& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template ostream& operator<<(ostream& os, const vector>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} template void chmin(T& a, T b){a = min(a, b);} template void chmax(T& a, T b){a = max(a, b);} int main(){ int n; cin >> n; vector x(n), y(n); rep(i, n) cin >> x[i] >> y[i]; map, vector>> ma; vector> v = {{0, 2, 1}, {0, 2, -1}, {1, 1, 2}, {1, -1, 2}, {2, -2, 1}, {2, -2, -1}, {3, 1, -2}, {3, -1, -2}}; rep(i, n){ for(auto [dir, dy, dx] : v){ pair p = {y[i] + dy, x[i] + dx}; if(ma.find(p) == ma.end()) ma[p].resize(4); ma[p][dir].push_back(i); } } { vector> del; rep(i, n){ pair p = {y[i], x[i]}; if(ma.find(p) == ma.end()) continue; del.push_back(p); } for(auto p : del) ma.erase(p); } const int INF = 1001001; vector dp(1 << n, INF); dp[0] = 0; for(auto& [p, vec] : ma){ vector dp_old(1 << n, INF); swap(dp, dp_old); rep(bit, 1 << n){ int bit_new = bit; rep(dir, 4) for(auto idx : vec[dir]) bit_new |= (1 << idx); chmin(dp[bit_new], dp_old[bit] + 1); chmin(dp[bit], dp_old[bit]); } } int ans = dp[(1 << n) -1]; if(ans >= INF) cout << "-1\n"; else cout << ans << "\n"; return 0; }