#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, e) for(int i = (int)(s); i < (int)(e); ++i)
#define rep(i, n) REP(i, 0, n)

#define X real()
#define Y imag()
#define curr(P, i) P[(i)%P.size()]
#define next(P, i) curr(P, (i+1))
#define prev(P, i) curr(P, (i-1+P.size()))
using D = double;
const D EPS = 1e-8;
using P = complex<D>;
using G = vector<P>;
namespace std {
    bool operator < (const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
};
D dot(const P& a, const P& b) {
    return (conj(a)*b).X;
}
D cross(const P& a, const P& b) {
    return (conj(a)*b).Y;
}
int ccw(P a, P b, P c) {
    b -= a; c -= a;
    if (cross(b, c) > 0)   return +1;       // counter clockwise
    if (cross(b, c) < 0)   return -1;       // clockwise
    if (dot(b, c) < 0)     return +2;       // c--a--b on line
    if (norm(b) < norm(c)) return -2;       // a--b--c on line
    return 0;
}
struct L : public vector<P> {
    L(const P &a, const P &b) {
        push_back(a); push_back(b);
    }
};
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
void f(L& l) {
    auto v = l[1] - l[0];
    l[0] += v*EPS;
    l[1] -= v*EPS;
}
bool isHitGG(const G& a, const G& b) {
    rep(i, a.size()) {
        L s = {curr(a, i), next(a, i)};
        f(s);
        rep(j, b.size()) {
            L t = {curr(b, j), next(b, j)};
            f(t);
            if(intersectSS(s, t)) return true;
        }
    }
    return false;
}
bool isHitGsGs(const vector<G>& a, const vector<G>& b) {
    for(auto&& g : a) for(auto&& h : b) {
        if(isHitGG(g, h)) return true;
    }
    return false;
}

int main() {
    int n;
    while(cin >> n) {
        if(n == 0) break;
        map<string, int> mp;
        vector<vector<G>> gs;
        rep(i, n) {
            string s;
            cin >> s;
            if(mp.count(s) == 0) {
                mp[s] = gs.size();
                gs.push_back({});
            }
            G g;
            {
                int x, y;
                while(cin >> x) {
                    if(x == -1) break;
                    cin >> y;
                    g.push_back({(D)x, (D)y});
                }
            }
            gs[mp[s]].push_back(g);
        }
        int m = mp.size();
        vector<set<int>> sts(m);//同色で塗れるidx
        rep(i, m) {
            rep(j, i) {
                if(!isHitGsGs(gs[i], gs[j])) {
                    sts[i].insert(j);
                    sts[j].insert(i);
                }
            }
        }
        const int INF = 1e9;
        vector<int> dp(1<<m, INF);
        dp[0] = 0;
        REP(mask, 1, 1<<m) {
            bool f = true;
            rep(i, m) rep(j, i) {
                if((mask&(1<<i)) && (mask&(1<<j))) {
                    if(sts[i].count(j) == 0) f = false;
                }
            }
            if(f) {
                dp[mask] = 1;
            }
        }
        REP(mask, 1, 1<<m) {
            for(int A = (mask-1); A > 0; A = (A-1)&mask) {
                int B = mask - A;
                dp[mask] = min(dp[mask], dp[A]+dp[B]);
            }
        }
        cout << dp[(1<<m)-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3252