//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

class Point{
public:
	int x, y;

	Point(double x = 0.0, double y = 0.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 a){ return Point(a*x, a*y); }
	Point operator / (double a){ return Point(x / a, y / a); }

	double abs(){ return sqrt(norm()); }
  int norm(){ return x*x + y*y; }

	bool operator < (const Point &p) const{
		return x != p.x ? x < p.x : y < p.y;
	}

	bool operator == (const Point &p) const {
		return x == p.x && y == p.y;
	}

  bool operator != (const Point &p) const {
	return !(*this == p);
  }

};

class Segment{
public:
	Point p1, p2;
};
typedef vector<Point> Polygon;

//???????????¨????????±???
typedef Point Vector;
//???????????´?????¨????????±???
typedef Segment Line;
int dot(Vector a, Vector b){
	return a.x*b.x + a.y*b.y;
}
int cross(Vector a, Vector b){
	return a.x*b.y - a.y*b.x;
}
int ccw(Point p0, Point p1, Point p2){

	//p0->p1???p0?§???????p1?????????????????????????????¨????????¨???

	//p0->p2??????????¨??????????????????¨???
	static const int COUNTER_CLOCKWISE = 1;
	//p0->p2???????¨??????????????????¨???
	static const int CLOCKWISE = -1;
	//p2,p0,p1????????§????????´?????????????????¨???
	static const int ONLINE_BACK = 2;
	//p0,p1,p2 ????????§????????´?????????????????´???
	static const int ONLINE_FRONT = -2;
	//p2 ????????? p0p1 ??????????????´???
	static const int ON_SEGMENT = 0;

	Vector a = p1 - p0;
	Vector b = p2 - p0;

	if (cross(a, b) >0) return COUNTER_CLOCKWISE;
	if (cross(a, b) < 0) return CLOCKWISE;
	if (dot(a, b) <= 0) return ONLINE_BACK;
	if (a.norm() <= b.norm()) return ONLINE_FRONT;

	return ON_SEGMENT;
}

bool intersect(Segment s1, Segment s2){
  int c1 = ccw(s1.p1, s1.p2, s2.p1);
  int c2 = ccw(s1.p1, s1.p2, s2.p2);
  switch(c1){
  case 2:
	return (c2 == -2 || c2 == 0);
  case -2:
	return (c2 == 2 || c2 == 0);
  case 0:
	return (c2 == 2 || c2 == 0 || c2 == -2);
  }
  return false;
}

const int INF = 1e9;

int bc(int b){
  int res = 0;
  while(b > 0){
	res += b&1;
	b >>= 1;
  }
  return res;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  while(cin>>N,N){
	VS name(N);
	map<string,int> id;
	vector<Polygon> poly(N);
	REP(i,N){
	  cin >> name[i];
	  if(!id.count(name[i])) id[name[i]] = SZ(id)-1;
	  while(true){
		int x; cin >> x;
		if(x < 0) break;
		int y; cin >> y;
		poly[i].PB(Point(x,y));
	  }
	}

	int M = SZ(id);
	vector<vector<bool>> xs(M, vector<bool>(M, false));
	REP(i,N) FOR(j,i+1,N){
	  if(name[i] == name[j]) continue;
	  bool ok = false;
	  for(int i_=0;i_<SZ(poly[i]);++i_){
		Segment l1;
		l1.p1 = poly[i][i_];
		l1.p2 = poly[i][(i_+1)%SZ(poly[i])];
		for(int j_=0;j_<SZ(poly[j]);++j_){
		  Segment l2;
		  l2.p1 = poly[j][j_];
		  l2.p2 = poly[j][(j_+1)%SZ(poly[j])];
		  if(intersect(l1,l2) || intersect(l2,l1)) ok = true;
		}
	  }
	  if(ok){
		int id1 = id[name[i]], id2 = id[name[j]];
		if(id1 < id2) swap(id1, id2);
		xs[id1][id2] = xs[id2][id1] = true;
	  }
	}

	VI dp(1<<11, INF);
	dp[0] = 0;
	for(int s=1;s<1<<M;++s){
	  for(int i=s;i>=0;--i){
		i &= s;
		int nt = s & (~i);
		bool ok = true;
		REP(k,M){
		  if(nt>>k&1);else continue;
		  REP(j,M){
			if(nt>>j&1); else continue;
			if(xs[k][j]) ok = false;
		  }
		}
		if(ok) dp[s] = min(dp[s], dp[i]+1);
	  }
	}
	cout << dp[(1<<M)-1] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1248