#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pi M_PI
#define inf 1<<30
#define eps (1e-11)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;

class Point{
public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}

  Point operator+(Point p){ return Point(x+p.x,y+p.y);}
  Point operator-(Point p){ return Point(x-p.x,y-p.y);}
  Point operator*(double k){ return Point(x*k,y*k);}
  Point operator/(double k){ return Point(x/k,y/k);}
  bool operator<(Point p)const{ return (x!=p.x ? x<p.x : y<p.y);}
  bool operator==(Point p)const{ return fabs(x-p.x)<eps && fabs(y-p.y)<eps;}

  double abs(){ return sqrt(norm());}
  double norm(){ return (x*x+y*y);}
};
typedef Point Vector;
typedef vector<Point> Polygon;

class Segment{
public:
  Point p1,p2;
  Segment(Point p1,Point p2):p1(p1),p2(p2){}
};
typedef Segment Line;

double norm(Vector a){ return (a.x*a.x+a.y*a.y);}
double abs(Vector a){ return sqrt(norm(a));}
double dot(Vector a,Vector b){ return (a.x*b.x+a.y*b.y);}
double cross(Vector a,Vector b){ return (a.x*b.y-a.y*b.x);}

bool isParallel(Vector a,Vector b){
  return equals(cross(a,b),0.0);
}

static const int COUNTER_CLOCKWISE=1;
static const int CLOCKWISE=-1;
static const int ONLINE_BACK=2;
static const int ONLINE_FRONT=-2;
static const int ON_SEGMENT=0;

int ccw(Point p0,Point p1,Point p2){
  Vector a=p1-p0;
  Vector b=p2-p0;
  if(cross(a,b)>eps)return COUNTER_CLOCKWISE;
  if(cross(a,b)<-eps)return CLOCKWISE;
  if(dot(a,b)<-eps)return ONLINE_BACK;
  if(a.norm()<b.norm())return ONLINE_FRONT;
  return ON_SEGMENT;
}

int n,x,y,ans=inf,num;
vector<Segment> v[20];
bool bo[20][20];
int color[20];

void init(){
  for(int i=0;i<20;i++){
    for(int j=0;j<20;j++)bo[i][j]=false;
    v[i].clear();
    color[i]=0;
  }
}

bool touch(int a,int b){
  for(int i=0;i<v[a].size();i++){
    for(int j=0;j<v[b].size();j++){
      Point A=v[a][i].p1,B=v[a][i].p2,
	    C=v[b][j].p1,D=v[b][j].p2;
      if(isParallel(A-B,C-D)){
	int c1=ccw(C,D,A),c2=ccw(C,D,B);
	if(c1==0 && c2==0)return true;
	if(c1==0 && !(A==C) && !(A==D))return true;
	if(c2==0 && !(B==C) && !(B==D))return true;
      }
    }
  }
  return false;
}

void dfs(int index,int sum){
  bool b[20]={};
  for(int i=0;i<num;i++){
    if(bo[index][i])b[color[i]]=true;
  }
  if(index==num-1){
    for(int i=1;i<=sum+1;i++){
      if(!b[i]){
	ans=min(ans,max(i,sum));
	return;
      }
    }
  }
  else {
    for(int i=1;i<=sum+1;i++){
      if(!b[i]){
	color[index]=i;
	dfs(index+1,max(i,sum));
	color[index]=0;
      }
    }
  }
}

int main()
{

  while(1){
    cin>>n;
    if(n==0)break;

    init();

    map<string,int> M;
    num=0;
    string s;

    for(int i=0;i<n;i++){
      cin>>s;
      vector<Point> vp;
      while(1){
	cin>>x;
	if(x==-1)break;
	cin>>y;
	vp.push_back(Point(x,y));
      }
      if(M.find(s)==M.end()){
	M[s]=num;
	for(int j=0;j<vp.size();j++){
	  v[num].push_back(Segment(vp[j],vp[(j+1)%vp.size()]));
	}		   
	num++;
      }
      else {
	for(int j=0;j<vp.size();j++){
	  v[M[s]].push_back(Segment(vp[j],vp[(j+1)%vp.size()]));
	}
      }
    }

    for(int i=0;i<num;i++){
      for(int j=0;j<num;j++){
	if(i==j)continue;
	if(!touch(i,j))continue;
	bo[i][j]=true;
	bo[j][i]=true;
      }
    }
    ans=inf;
    dfs(0,0);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1264