#include using namespace std; template istream& operator >> (istream& is, vector& vec) { for(T& x : vec) is >> x; return is; } template ostream& operator << (ostream& os, const vector& vec) { if(vec.empty()) return os; os << vec[0]; for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it; return os; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector> p(n), p2, dir = {{2, 1}, {-2, 1}, {1, 2}, {1, -2}}; for(auto &&[x, y] : p){ cin >> x >> y; //cerr << x << " " << y << '\n'; for(int i = 0; i < 4; i++){ p2.emplace_back((i >> 1 & 1 ? -2 : 2) + x, (i & 1 ? -1 : 1) + y); p2.emplace_back((i & 1 ? -1 : 1) + x, (i >> 1 & 1 ? -2 : 2) + y); } } sort(p2.begin(), p2.end()); p2.erase(unique(p2.begin(), p2.end()), p2.end()); sort(p.begin(), p.end()); vector dp(1 << n, 1 << 30); dp[0] = 0; for(auto &&[x, y] : p2){ if(binary_search(p.begin(), p.end(), make_pair(x, y))) continue; vector ndp = dp; for(auto &&[dy, dx] : dir){ int y1 = dy + y, x1 = dx + x; int y2 = (dy == 1 ? -dy : dy) + y, x2 = (dx == 1 ? -dx : dx) + x; int S = 0; int j = lower_bound(p.begin(), p.end(), make_pair(x1, y1)) - p.begin(); if(j < n && x1 == p[j].first && y1 == p[j].second){ S |= 1 << j; } j = lower_bound(p.begin(), p.end(), make_pair(x2, y2)) - p.begin(); if(j < n && x2 == p[j].first && y2 == p[j].second){ S |= 1 << j; } if(S == 0) continue; for(int U = (1 << n) - 1; U >= 0; U--){ ndp[U | S] = min(ndp[U | S], dp[U] + 1); } } swap(dp, ndp); } //cerr << dp << '\n'; cout << (dp.back() >> 30 & 1 ? -1 : dp.back()) << '\n'; }