#include <bits/stdc++.h>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
bool exist[1100][10];
struct State {
    bitset<10> bit;
    int t;
    State() {
        t = 0;
        bit = 0;
    }
    void show() {
        cerr << bit << endl;
        cerr << "t:" << t << endl;
    }
    bool operator<(const State &b) { return t < b.t; }
};
bool ign(State &a, State &b) {
    if (!a.bit[b.t] && !b.bit[a.t]) return true;
    REP(i, 10) {
        if (a.bit[i] && b.bit[i]) return true;
    }
    return false;
}
bool dead(State &a, State &b) {
    if (a.bit[b.t] && b.bit[a.t]) return true;
    return false;
}
bool canmerge(State &a, State &b) { return (a.bit[b.t] && !b.bit[a.t]) || (!a.bit[b.t] && b.bit[a.t]); }
State merge(State &a, State &b) {
    State nw;
    if (a.bit[b.t] && !b.bit[a.t]) {
        nw.bit = a.bit | b.bit;
        nw.t = a.t;
        return nw;
    } else if (!a.bit[b.t] && b.bit[a.t]) {
        nw.bit = a.bit | b.bit;
        nw.t = b.t;
        return nw;
    } else {
        cerr << "cannot merge!!!!!" << endl;
    }
}
bool solve() {
    int N;
    cin >> N;
    REP(i, 1 << 10) REP(j, 10) exist[i][j] = false;
    if (N == 0) return false;
    string S;
    cin >> S;
    // set<State> ss;
    State now;
    vector<State> vs;
    REP(i, N) {
        if (S[i] == 'u') {
            now.t = 0;
            now.bit = 0;
        } else {
            int num = S[i] - '0';
            now.t = num;
            if (now.bit[now.t]) {
                cout << "UNSAFE" << endl;
                return true;
            }
            int bi = now.bit.to_ulong();
            if (!exist[bi][now.t]) {
                exist[bi][now.t] = true;
                // ss.insert(now);
                // now.show();
                vs.push_back(now);
            }

            now.bit[now.t] = true;
        }
    }

    // for (auto s : ss) vs.push_back(s);
    bool found = true;
    while (found) {
        found = false;
        int n = vs.size();
        REP(i, n) {
            FOR(j, i + 1, n) {
                if (ign(vs[i], vs[j])) continue;
                if (dead(vs[i], vs[j])) {
                    // vs[i].show();
                    // vs[j].show();
                    cout << "UNSAFE" << endl;
                    return true;
                }
                State nw = merge(vs[i], vs[j]);
                int bi = nw.bit.to_ulong();
                if (!exist[bi][nw.t]) {
                    found = true;
                    vs.push_back(nw);
                    // ss.insert(nw);
                    exist[bi][nw.t] = true;
                }
            }
        }
    }
    cout << "SAFE" << endl;
    return true;
}
signed main() {
    while (solve())
        ;
}
