#include <bits/stdc++.h>
using namespace std;

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

pii operator-(const pii &a,const pii &b){
    return make_pair(a.first-b.first,a.second-b.second);
}

void solve(int n){
    map<string,int> t;
    vector<vector<int>> vs;
    vector<vector<pii>> ps(n);
    int size=0;
    rep(i,0,n){
        string str;
        cin >> str;
        if(t.find(str)==t.end()){
            t[str]=size;
            vs.push_back(vector<int>());
            ++size;
        }
        vs[t[str]].push_back(i);
        while(true){
            int x,y;
            cin >> x;
            if(x==-1) break;
            cin >> y;
            ps[i].push_back(make_pair(x,y));
        }
    }

    auto cross=[](pii &a,pii &b){
        return a.first*b.second-a.second*b.first;
    };

    vector<vector<int>> graph(size);
    rep(i,0,size) rep(j,0,i){
        if([&](){
            rep(k,0,vs[i].size()) rep(l,0,vs[j].size()){
                rep(i_,0,ps[vs[i][k]].size()) rep(j_,0,ps[vs[j][l]].size()){
                    pii &p1=ps[vs[i][k]][i_],&p2=ps[vs[i][k]][(i_+1)%ps[vs[i][k]].size()];
                    pii &q1=ps[vs[j][l]][j_],&q2=ps[vs[j][l]][(j_+1)%ps[vs[j][l]].size()];
                    pii a=p1-p2,b=q1-q2;
                    pii c=p1-q1,d=p2-q2;
                    pii e=p1-q2,f=p2-q1;
                    if(cross(a,b) or cross(c,d) or cross(e,f)) continue;
                    if(a.first and (max(p1.first,p2.first)<=min(q1.first,q2.first) or max(q1.first,q2.first)<=min(p1.first,p2.first))) continue;
                    if(a.second and (max(p1.second,p2.second)<=min(q1.second,q2.second) or max(q1.second,q2.second)<=min(p1.second,p2.second))) continue;
                    return true;
                }
            }
            return false;
        }()){
            graph[i].push_back(j);
            graph[j].push_back(i);
        }
    }

    vector<int> dp(1<<size,inf);
    dp[0]=0;
    rep(i,0,size) dp[1<<i]=1;
    rep(s,0,1<<size) rep(t,0,1<<size){
        if((s&t)!=t or (s|t)!=s) continue;
        if(![&](){
            int d=s&~t;
            rep(i,0,size){
                if(!((d>>i)&1)) continue;
                for(int j:graph[i]) if((d>>j)&1) return false;
            }
            return true;
        }()) continue;
        dp[s]=min(dp[s],dp[t]+1);
    }

    cout << dp[(1<<size)-1] << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    while(true){
        int n;
        cin >> n;
        if(!n) break;
        solve(n);
    }
    return 0;
}

Measured memory_bytes: 3128