#include <bits/stdc++.h>

using namespace std;

#define EQ(x, y) (abs((x) - (y)) < EPS)

namespace {

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }

    double EPS = 1e-6;

    struct Point {
        double x, y;
        Point() {}
        Point(double x, double y) : x(x), y(y) {}
        Point operator+(const Point& p) const { return Point(x + p.x, y + p.y); }
        Point operator-(const Point& p) const { return Point(x - p.x, y - p.y); }
        Point operator*(double k) const { return Point(k * x, k * y); }
        Point operator/(double k) const { return Point(x / k, y / k); }
        bool operator==(const Point& p) const { return EQ(x, p.x) && EQ(y, p.y); }
    };
    double dot(const Point& a, const Point& b) { return a.x * b.x + a.y * b.y; }
    double cross(const Point& a, const Point& b) { return a.x * b.y - a.y * b.x; }
    double norm(const Point& a) { return sqrt(dot(a, a)); }
    Point rot90(const Point& p) { return Point(-p.y, p.x); } // 反時計回りに90度回転 
    double angle(const Point& a) { return atan2(a.y, a.x); } // x軸を反時計回りに何ラジアン回転させれば点aに乗るか
    ostream& operator<<(ostream& os, const Point& p) { return os << "(" << p.x << "," << p.y << ")"; }
    istream& operator>>(istream& is, Point& p) { return is >> p.x >> p.y; }

    struct Segment {
        Point a, b;
        Segment() {}
        Segment(const Point& a, const Point& b) : a(a), b(b) {}
        bool operator==(const Segment& s) const {
            return (a == s.a && b == s.b) || (b == s.a && a == s.b);
        }
    };
    ostream& operator<<(ostream& os, const Segment& s) {
        return os << "(" << s.a << "," << s.b << ")";
    }

    typedef vector<Point> Polygon;

    int ccw(Point a, Point b, Point c){
        b = b - a; c = c - a;
        if (cross(b, c) > EPS) return +1;      // a,b,cの順に反時計周り
        if (cross(b, c) < -EPS) return -1;     // a,b,cの順に時計周り
        if (dot(b, c) < 0) return +2;          // c--a--b 直線
        if (norm(b) < norm(c)) return -2;      // a--b--c 直線
        return 0;                              // a--c--b 直線
    }

    int N;
    int n;
    map<string, int> id;
    vector<string> names;
    vector<Polygon> P;
    bool input() {
        cin >> N;
        if (N == 0) return false;
        id.clear();
        names.clear();
        P.clear(); P.resize(N);
        n = 0;
        for (int i = 0; i < N; i++) {
            string s; cin >> s;
            names.push_back(s);
            if (id.count(s) == 0) {
                id[s] = n++;
            }
            while (true) {
                int x; cin >> x;
                if (x < 0) break;
                int y; cin >> y;
                P[i].push_back(Point(x, y));
            }
        }
        return true;
    }

    bool parallel(const Segment& s, const Segment& t) { return abs(cross(s.b - s.a, t.b - t.a)) < EPS; }

    bool contains(const Segment& s, const Point& p) {
        if (s.a == p) return false;
        if (s.b == p) return false;
        return ccw(s.a, s.b, p) == 0;
    }

    bool touch(const Polygon& a, const Polygon& b) {
        int na = int(a.size());
        int nb = int(b.size());
        for (int i = 0; i < na; i++) {
            Segment s(a[i], a[(i + 1) % na]);
            for (int j = 0; j < nb; j++) {
                Segment t(b[j], b[(j + 1) % nb]);
                if (s == t) return true;
                if (!parallel(s, t)) continue;
                if ((contains(s, t.a) || contains(s, t.b)) || 
                            (contains(t, s.a) || contains(t, s.b))) {
                    return true;
                }
            }
        }
        return false;
    }

    vector< vector<bool> > G;

    bool check(vector<int>& cs) {
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if (G[i][j] && cs[i] == cs[j]) return false;
            }
        }
        return true;
    }

    int count(vector<int>& cs) {
        vector<bool> used(n, false);
        int ret = 0;
        for (int i = 0; i < n; i++) {
            if (cs[i] < 0) continue;
            if (used[cs[i]]) continue;
            used[ cs[i] ] = true;
            ret++;
        }
        return ret;
    }

    int dfs(int v, vector<int>& cs) {
        if (v == n) return (check(cs) ? count(cs) : 11);
        int ret = 11;
        for (int i = 0; i <= v; i++) {
            int c = 0;
            for (int j = 0; j < n; j++) {
                if (G[v][j] && cs[j] == i) goto next;
            }
            cs[v] = i;
            ret = min(ret, dfs(v + 1, cs));
            cs[v] = -1;
next:;
        }
        return ret;
    }

    void solve() {
        G.clear(); G.resize(n, vector<bool>(n, false));
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                int x = id[ names[i] ];
                int y = id[ names[j] ];
                if (x == y) continue;
                if (touch(P[i], P[j])) {
                    G[x][y] = G[y][x] = true;
                }
            }
        }
        vector<int> cs(n, -1);
        cs[0] = 0;
        cout << dfs(1, cs) << endl;
    }
}

int main() {
    while (input()) solve();
    return 0;
}

Measured memory_bytes: 1252