#include using namespace std; // #define int long long using ll= long long; #define fo(i,b) for(int i = (0); i < (b); ++i) #define f(i,a,b) for(int i = (a); i < (b); ++i) #define rep(i,a,b) for(int i = (a); i < (b); ++i) typedef pair pii; typedef vector vi; #define D if(0) const int NMAX = 112345; const ll LC = 2123456789; const ll NONE = 1003456789; struct P{ vector near; int comp; }; unordered_map p; unordered_map comp_con; ll dirs[4] = {-1, 1, -LC, LC}; void resp(int v){ printf("%d\n", v); exit(0); } void go_comp(ll x, ll from, int comp) { if(p.count(x)){ if(p[x].comp) resp(0); else { p[x].comp = comp; for(ll near: p[x].near) { if(near != from) go_comp(near, x, comp); } } } } signed main() { int n; scanf("%d", &n); fo(i,n) { int a,b,c,d; scanf("%d%d%d%d", &a, &b, &c, &d); ll x = a*LC + b; ll y = c*LC + d; p[x].near.push_back(y); p[y].near.push_back(x); } int comp_aloc=1; for(auto it: p){ ll x= it.first; P str = it.second; if(!str.comp) go_comp(x, NONE, ++comp_aloc); } for(auto it: p){ ll x= it.first; P str = it.second; for(ll d : dirs) { for(ll near: p[x].near) if(x+d == near) goto next; if(p.count(x+d)) { if(p[x+d].comp == str.comp) resp(1); ll cp = str.comp*LC + p[x+d].comp; comp_con[cp]++; } next:; } } for(auto it: comp_con) if(it.second > 1) resp(2); for(auto it: p){ ll x= it.first; P str = it.second; if(str.near.size() >=2) { if(str.near.size() >=3) resp(2); ll a = str.near[0]; ll b = str.near[1]; if(a+b != x+x) resp(2); } } if(n) resp(3); resp(4); }