#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;


long long power(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

int Chromatic(vector<vector<int> > graph) {
    int n = graph.size();
    vector<int> G(n, 0);
    for (int i = 0; i < n; ++i) {
        G[i] |= (1<<i);
        for (int j = 0; j < n; ++j)
            if (graph[i][j])
                G[i] |= (1<<j);
    }
    vector<int> I(1<<n);
    I[0] = 1;
    for (int s = 1; s < (1<<n); ++s) {
        //int v = __builtin_ctz(s);
		int v = 0;
		for (int i = 0; i < n; ++i) {
			if (s & (1<<i)) break;
			++v;
		}
        I[s] = I[s^(1<<v)] + I[s&~G[v]];
    }
    int lo = 0, up = n, med;
    while (up - lo > 1) {
        med = (up + lo) >> 1;
        int g = 0;
        for (int s = 0; s < (1<<n); ++s) {
			int v = 0;
			for (int i = 0; i < n; ++i) if (s & (1<<i)) ++v;
            if (v & 1) g -= power(I[s], med);
            else g += power(I[s], med);
        }
        if (g != 0) up = med;
        else lo = med;
    }
    return up;
}

typedef double DD;

const DD INF = 1LL<<60;
const DD EPS = 1e-10;
const DD PI = acos(-1.0);
DD torad(int deg) {return (DD)(deg) * PI / 180;}
DD todeg(DD ang) {return ang * 180 / PI;}

struct Point {
    DD x, y;
    Point(DD x = 0.0, DD y = 0.0) : x(x), y(y) {}
    friend ostream& operator << (ostream &s, const Point &p) {return s << '(' << p.x << ", " << p.y << ')';}
};

Point operator + (const Point &p, const Point &q) {return Point(p.x + q.x, p.y + q.y);}
Point operator - (const Point &p, const Point &q) {return Point(p.x - q.x, p.y - q.y);}
Point operator * (const Point &p, DD a) {return Point(p.x * a, p.y * a);}
Point operator * (DD a, const Point &p) {return Point(a * p.x, a * p.y);}
Point operator * (const Point &p, const Point &q) {return Point(p.x * q.x - p.y * q.y, p.x * q.y + p.y * q.x);}
Point operator / (const Point &p, DD a) {return Point(p.x / a, p.y / a);}
Point conj(const Point &p) {return Point(p.x, -p.y);}
Point rot(const Point &p, DD ang) {return Point(cos(ang) * p.x - sin(ang) * p.y, sin(ang) * p.x + cos(ang) * p.y);}
Point rot90(const Point &p) {return Point(-p.y, p.x);}
DD cross(const Point &p, const Point &q) {return p.x * q.y - p.y * q.x;}
DD dot(const Point &p, const Point &q) {return p.x * q.x + p.y * q.y;}
DD norm(const Point &p) {return dot(p, p);}
DD abs(const Point &p) {return sqrt(dot(p, p));}
DD amp(const Point &p) {DD res = atan2(p.y, p.x); if (res < 0) res += PI*2; return res;}
bool eq(const Point &p, const Point &q) {return abs(p - q) < EPS;}
bool operator < (const Point &p, const Point &q) {return (abs(p.x - q.x) > EPS ? p.x < q.x : p.y < q.y);}
bool operator > (const Point &p, const Point &q) {return (abs(p.x - q.x) > EPS ? p.x > q.x : p.y > q.y);}
Point operator / (const Point &p, const Point &q) {return p * conj(q) / norm(q);}

struct Line : vector<Point> {
    Line(Point a = Point(0.0, 0.0), Point b = Point(0.0, 0.0)) {
        this->push_back(a);
        this->push_back(b);
    }
    friend ostream& operator << (ostream &s, const Line &l) {return s << '{' << l[0] << ", " << l[1] << '}';}
};

int ccw(const Point &a, const Point &b, const Point &c) {
    if (cross(b-a, c-a) > EPS) return 1;
    if (cross(b-a, c-a) < -EPS) return -1;
    if (dot(b-a, c-a) < -EPS) return 2;
    if (norm(b-a) < norm(c-a) - EPS) return -2;
    return 0;
}

int n;
map<string, vector<vector<Point> > > ma;

bool issame(Line l, Line s) {
	for (int it = 0; it < 2; ++it) {
		if (it == 1) swap(l, s);
		if ( !eq(l[0], s[0]) && !eq(l[0], s[1]) && ccw(s[0], s[1], l[0]) == 0 ) return true;
		if ( !eq(l[1], s[0]) && !eq(l[1], s[1]) && ccw(s[0], s[1], l[1]) == 0 ) return true;
		if ( eq(l[0], s[0]) && eq(l[1], s[1]) ) return true;
		if ( eq(l[0], s[1]) && eq(l[1], s[0]) ) return true;
	}
	return false;
}

int main() {
    //freopen( "/Users/macuser/Dropbox/Contest/input.in", "r", stdin );
    
	while (cin >> n) {
		if (n == 0) break;
		ma.clear();
		for (int i = 0; i < n; ++i) {
			string str; cin >> str;
			vector<Point> vp;
			int a, b;
			while (cin >> a) {
				if (a == -1) break;
				cin >> b;
				Point p(a, b);
				vp.push_back(p);
			}
			ma[str].push_back(vp);
		}
		int V = ma.size();
		vector<vector<int> > G(V, vector<int>(V, 0));

		//COUT(ma);
		
		int i = 0, j = 0;
		for (map<string, vector<vector<Point> > >::iterator it1 = ma.begin(); it1 != ma.end(); ++it1) {
			j = 0;
			for (map<string, vector<vector<Point> > >::iterator it2 = ma.begin(); it2 != ma.end(); ++it2) {
				if (i == j) { ++j; continue; }
				bool adj = false;
				
				for (int x = 0; x < (it1->second).size(); ++x) for (int y = 0; y < (it2->second).size(); ++y) {
					vector<Point> vp1 = (it1->second)[x], vp2 = (it2->second)[y];
					for (int p = 0; p < vp1.size(); ++p) for (int q = 0; q < vp2.size(); ++q) {
						//cout << p << ", " << q << endl;
						Line l(vp1[p], vp1[ (p+1)%vp1.size() ]);
						Line m(vp2[q], vp2[ (q+1)%vp2.size() ]);
						if (issame(l, m)) adj = true;
					}
				}
				if (adj) G[i][j] = true;
				++j;
			}
			++i;
		}

		//COUT(G);

		int res = Chromatic(G);
		cout << res << endl;
	}
    return 0;
}
