#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<algorithm>
using namespace std;
const double INF=1e14;
const double eps=1e-8;
const double Pi=acos(-1.0);
int cmp (double A){
	if(fabs(A)<eps)return 0;
	else return A>0?1:-1;
}
bool equal(double A,double B){
	return cmp(A-B)==0;
}
struct Point{
	double x,y;
	Point(double _x=0,double _y=0):x(_x),y(_y){}
	friend Point operator + (const Point &A,const Point &B){return Point(A.x+B.x,A.y+B.y);}
	friend Point operator - (const Point &A,const Point &B){return Point(A.x-B.x,A.y-B.y);}
	friend double operator * (const Point &A,const Point &B){return A.x*B.x+A.y*B.y;}
	friend double operator ^ (const Point &A,const Point &B){return A.x*B.y-A.y*B.x;}
	double ang(){
		return atan2(y,x);
	}
	void read(){
		scanf("%lf%lf",&x,&y);
	}
	void write(){
		printf("%lf %lf\n",x,y);
	}
};
struct Square{
	Point A,B,C,D;
	void read(){
		A.read();C.read();
		B.x=C.x;B.y=A.y;
		D.x=A.x;D.y=C.y;
	}
	void write(){
		cout<<"Print\n";
		A.write();
		B.write();
		C.write();
		D.write();
		cout<<'\n';
	}
}A[3001];
struct area{
	double l,r;
	int Id;
}L[6001];
int n;
bool Check(Square A){
	return cmp(A.A.x)==-1&&cmp(A.C.x)==-1&&cmp(A.A.y)==-1&&(cmp(A.C.y)>=0);
}
bool cmpL (area A,area B){
	return cmp(A.l-B.l)==-1||(equal(A.l,B.l)&&A.r>B.r);
}
bool vis[2001];
int main(){
//	freopen("Aizu2472.in","r",stdin);
//	freopen("Aizu2472.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		A[i].read();
		if(Check(A[i])){
			L[i].r=A[i].B.ang();
			L[i].l=A[i].C.ang()-2*Pi;
			L[i].Id=i;
//			cout<<A[i].B.ang()<<" "<<A[i].C.ang()<<'\n';
			continue;
		}
		L[i].l=INF;
		L[i].r=-INF;
		
		L[i].l=min(L[i].l,A[i].A.ang());
		L[i].r=max(L[i].r,A[i].A.ang());
		
		L[i].l=min(L[i].l,A[i].B.ang());
		L[i].r=max(L[i].r,A[i].B.ang());
		
		L[i].l=min(L[i].l,A[i].C.ang());
		L[i].r=max(L[i].r,A[i].C.ang());
		
		L[i].l=min(L[i].l,A[i].D.ang());
		L[i].r=max(L[i].r,A[i].D.ang());
		
		L[i].Id=i;
	}
	for(int i=1;i<=n;++i){
		L[i+n].l=L[i].l+2*Pi;
		L[i+n].r=L[i].r+2*Pi;
		L[i+n].Id=L[i].Id;
	}
	sort(L+1,L+1+2*n,cmpL);
//	for(int i=1;i<=2*n;++i){
//		cout<<fixed<<setprecision(12)<<L[i].l<<" "<<L[i].r<<" "<<L[i].Id<<'\n';
//	}
	int ans=n+1;
	for(int i=1;i<=n;++i){
		int cost=1;
		double R=L[i].r;
		memset(vis,0,sizeof(vis));
		vis[L[i].Id]=1;
		for(int j=i+1;j<=2*n;++j){
//			if(cmp((L[j].l-L[i].l)-2*Pi)>=0)break;
			if(vis[L[j].Id])continue;
			vis[L[j].Id]=1;
			if(cmp(L[j].l-R)<=0)R=min(R,L[j].r);
			else cost++,R=L[j].r;
//			cout<<L[j].l<<" "<<L[j].r<<'\n';
//			cout<<fixed<<setprecision(10)<<R<<" "<<L[j].l<<'\n';
		}
//		for(int i=1;i<=n;++i){
//			if(!vis[i])cerr<<i<<" ";
//		}
		ans=min(ans,cost);
//		cout<<ans<<" "<<cost<<'\n';
	}
	cout<<ans<<'\n';
	return 0;
}
