#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int N,ans,country_index;

bool adj_check[10][10];

#define NUM 9999999.0

struct Point{
	double x,y;
};

struct Data{
	Data(double arg_value,bool arg_is_i){
		value = arg_value;
		is_i = arg_is_i;
	}
	bool operator<(const struct Data &arg) const{
		return value < arg.value;
	};
	double value;
	bool is_i;
};

typedef Point Vector;

struct Segment{
	void set(double x1,double y1,double x2,double y2){
		p1.x = x1;
		p1.y = y1;
		p2.x = x2;
		p2.y = y2;
	}
	Point p1,p2;
};

typedef Segment Line;

struct Region{
	vector<Line> Lines;
};

struct Country{
	int color;
	char name[21];
	vector<Region> regions;
};

struct Shishimaru{
	int colors[10];
};


void recursive(Shishimaru shishimaru,int count){

	if(count == country_index){

		int tmp_max = 0;

		for(int i = 0; i < country_index; i++){
			tmp_max = max(tmp_max,shishimaru.colors[i]);
		}

		ans  = min(ans,tmp_max);

		return;
	}

	for(int i = 0; i < country_index; i++){
		if(shishimaru.colors[i] != -1)continue;

		bool check[11];
		for(int k = 0; k < 11; k++)check[k] = false;

		for(int k = 0; k < country_index; k++){
			if(i != k && adj_check[i][k] == true && shishimaru.colors[k] != -1){
				check[shishimaru.colors[k]] = true;
			}
		}

		Shishimaru next_shishimaru;
		for(int k = 0; k < country_index; k++){
			next_shishimaru.colors[k] = shishimaru.colors[k];
		}

		for(int k = 1; k <= 10; k++){
			if(check[k] == false){
				next_shishimaru.colors[i] = k;
				break;
			}
		}

		recursive(next_shishimaru,count+1);
	}
}

int func(double x1,double y1,double x2, double y2, double xp, double yp){
	double naiseki,norm1,norm2,gaiseki;
	norm1 = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
	norm2 = sqrt((xp-x1)*(xp-x1)+(yp-y1)*(yp-y1));
	naiseki = (xp-x1)*(x2-x1)+(yp-y1)*(y2-y1);
	gaiseki = (x2-x1)*(yp-y1)-(xp-x1)*(y2-y1);
	if(gaiseki > EPS){
		return 1;
	}else if(gaiseki < -EPS){
		return -1;
	}
	if(naiseki < -EPS){
		return 2;
	}

	if(norm1 < norm2){
		return -2;
	}
	return 0;
}


bool strCmp(char* base, char* comp){
	int length1,length2;
	for(length1=0;base[length1] != '\0';length1++);
	for(length2=0;comp[length2] != '\0';length2++);
	if(length1 != length2)return false;

	for(int i=0;base[i] != '\0'; i++){
		if(base[i] != comp[i])return false;
	}
	return true;
}

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

double calc_slope(Line line){

	if(fabs(line.p1.y - line.p2.y) < EPS){
		return 0.0;
	}else if(fabs(line.p1.x - line.p2.x) < EPS){
		return NUM;
	}else{
		return (line.p1.y-line.p2.y)/(line.p1.x-line.p2.x);
	}
}

void solve(){

	Country country[N];
	country_index = 0;

	for(int i = 0; i < N; i++){
		country[i].color = -1;
	}

	char buf[21];

	int tmp_index;

	for(int loop = 0; loop < N; loop++){
		scanf("%s",buf);

		tmp_index = -1;
		for(int i = 0; i < country_index; i++){
			if(strCmp(country[i].name,buf)){
				tmp_index = i;
				break;
			}
		}
		if(tmp_index == -1){
			strcpy(country[country_index].name,buf);
			tmp_index = country_index;
			country_index++;
		}

		Region new_region;
		Line new_line;

		double x,y,pre_x = -1.0,pre_y = -1.0;

		while(true){
			scanf("%lf",&x);
			if(fabs(x + 1.0) < EPS){
				new_line.p1.x = pre_x;
				new_line.p1.y = pre_y;
				new_line.p2.x = new_region.Lines[0].p1.x;
				new_line.p2.y = new_region.Lines[0].p1.y;
				new_region.Lines.push_back(new_line);
				break;
			}
			scanf("%lf",&y);

			if(fabs(pre_x+1.0) > EPS){
				new_line.p1.x = pre_x;
				new_line.p1.y = pre_y;
				new_line.p2.x = x;
				new_line.p2.y = y;
				new_region.Lines.push_back(new_line);
			}

			pre_x = x;
			pre_y = y;
		}

		country[tmp_index].regions.push_back(new_region);
	}


	if(country_index == 1){
		printf("1\n");
		return;
	}

	for(int i = 0; i < country_index; i++){
		for(int k = 0; k < country_index; k++){
			adj_check[i][k] = false;
		}
	}

	bool adj_FLG;
	double tmp_slope;

	vector<Data> calc_V;

	for(int i = 0; i < country_index; i++){

		for(int k = 0; k < country_index; k++){
			if(i == k)continue;

			adj_FLG = false;

			for(int a = 0; a < country[i].regions.size(); a++){
				for(int b = 0; b < country[k].regions.size(); b++){
					for(int c = 0; c < country[i].regions[a].Lines.size(); c++){
						for(int d = 0; d < country[k].regions[b].Lines.size();d++){


							if(fabs((tmp_slope = calc_slope(country[i].regions[a].Lines[c])) - calc_slope(country[k].regions[b].Lines[d])) < EPS){

								calc_V.clear();

								if(fabs(tmp_slope) < EPS && country[i].regions[a].Lines[c].p1.y == country[k].regions[b].Lines[d].p1.y &&
										country[i].regions[a].Lines[c].p2.y == country[k].regions[b].Lines[d].p2.y){

									calc_V.push_back(Data(country[i].regions[a].Lines[c].p1.x,true));
									calc_V.push_back(Data(country[i].regions[a].Lines[c].p2.x,true));
									calc_V.push_back(Data(country[k].regions[b].Lines[d].p1.x,false));
									calc_V.push_back(Data(country[k].regions[b].Lines[d].p2.x,false));

									sort(calc_V.begin(),calc_V.end());

									if(calc_V[0].is_i != calc_V[1].is_i && fabs(calc_V[1].value - calc_V[2].value) > 0.1){
										adj_FLG = true;
										break;
									}
								}else if(fabs(tmp_slope-NUM) < EPS && country[i].regions[a].Lines[c].p1.x == country[k].regions[b].Lines[d].p1.x &&
										country[i].regions[a].Lines[c].p2.x == country[k].regions[b].Lines[d].p2.x){

									calc_V.push_back(Data(country[i].regions[a].Lines[c].p1.y,true));
									calc_V.push_back(Data(country[i].regions[a].Lines[c].p2.y,true));
									calc_V.push_back(Data(country[k].regions[b].Lines[d].p1.y,false));
									calc_V.push_back(Data(country[k].regions[b].Lines[d].p2.y,false));

									sort(calc_V.begin(),calc_V.end());

									if(calc_V[0].is_i != calc_V[1].is_i && fabs(calc_V[1].value - calc_V[2].value) > 0.1){
										adj_FLG = true;
										break;
									}
								}else if(fabs(tmp_slope-0.0) > EPS && fabs(tmp_slope-NUM) > EPS){

									if(func(country[i].regions[a].Lines[c].p1.x,country[i].regions[a].Lines[c].p1.y,
												country[i].regions[a].Lines[c].p2.x,country[i].regions[a].Lines[c].p2.y,
												country[k].regions[b].Lines[d].p1.x,country[k].regions[b].Lines[d].p1.y)*
										func(country[i].regions[a].Lines[c].p1.x,country[i].regions[a].Lines[c].p1.y,
												country[i].regions[a].Lines[c].p2.x,country[i].regions[a].Lines[c].p2.y,
												country[k].regions[b].Lines[d].p2.x,country[k].regions[b].Lines[d].p2.y) <= 0 &&
										func(country[k].regions[b].Lines[d].p1.x,country[k].regions[b].Lines[d].p1.y,
												country[k].regions[b].Lines[d].p2.x,country[k].regions[b].Lines[d].p2.y,
												country[i].regions[a].Lines[c].p1.x,country[i].regions[a].Lines[c].p1.y)*
										func(country[k].regions[b].Lines[d].p1.x,country[k].regions[b].Lines[d].p1.y,
												country[k].regions[b].Lines[d].p2.x,country[k].regions[b].Lines[d].p2.y,
												country[i].regions[a].Lines[c].p2.x,country[i].regions[a].Lines[c].p2.y) <= 0){

										calc_V.push_back(Data(country[i].regions[a].Lines[c].p1.x,true));
										calc_V.push_back(Data(country[i].regions[a].Lines[c].p2.x,true));
										calc_V.push_back(Data(country[k].regions[b].Lines[d].p1.x,false));
										calc_V.push_back(Data(country[k].regions[b].Lines[d].p2.x,false));

										sort(calc_V.begin(),calc_V.end());

										if(calc_V[0].is_i != calc_V[1].is_i && fabs(calc_V[1].value - calc_V[2].value) > 0.1){
											adj_FLG = true;
											break;
										}
									}
								}
							}
						}
						if(adj_FLG)break;
					}
					if(adj_FLG)break;
				}
				if(adj_FLG)break;
			}

			if(adj_FLG){
				adj_check[i][k] = true;
			}
		}
	}

	ans = BIG_NUM;

	for(int i = 0; i < country_index; i++){
		Shishimaru shishi;
		for(int k = 0; k < country_index; k++){
			shishi.colors[k] = -1;
		}
		shishi.colors[i] = 1;
		recursive(shishi,1);
	}

	printf("%d\n",ans);
}



int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		solve();
	}

	return 0;
}