#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using pi = pair<bitset<10>, int>;

int main()
{
    bool B[1 << 10][10];
    while (true)
    {
        int N; cin >> N;
        if(N == 0) return 0;
        string S; cin >> S;

        vector<pi> state;
        bitset<10> lock; 
        bool unsafe = false;
        memset(B, 0, sizeof(B));

        for(auto c : S)
        {
            if (c == 'u')
            {
                lock.reset();
            }
            else
            {
                int x = c - '0';
                if (lock[x])
                {
                    unsafe = true;
                    printf("UNSAFE\n");
                    break;
                }
                auto locks = pi(lock, x);
                if (!B[lock.to_ulong()][x])
                {
                    state.emplace_back(locks);
                    B[lock.to_ulong()][x] = true;
                }

                lock[x] = true;
            }                     
        }

        if(unsafe)continue;
        // for(auto p: state)
        // {
        //     cout << p.first <<  " " << p.second << "\n";
        // }

        vector<pi> single;
        for(auto p : state)
        {
            single.emplace_back(p);
        }

        rep(t, 9)
        {
            int N = state.size();
            rep(i, N)
            {
                rep(j, single.size())
                {
                    auto a = state[i].first;
                    auto b = single[j].first;

                    //ロックがかぶっていたら評価しない
                    if ((a & b).any())
                    {
                        continue;
                    }

                    int a_want = state[i].second;
                    int b_want = single[j].second;
                    if (a[b_want] && b[a_want])
                    {
                        unsafe = true;
                        printf("UNSAFE\n");
                        // cout << a << " " << a_want << " " << b << " "<< b_want << "\n";
                        // for (auto p : state)
                        // {
                        //     cout << p.first << " " << p.second << "\n";
                        // }
                        break;
                    }
                    if (!a[b_want] && b[a_want])
                    {
                        auto locks = pi(a | b, b_want);
                        if (!B[(a|b).to_ulong()][b_want])
                        {
                            state.emplace_back(locks);
                            B[(a|b).to_ulong()][b_want] = true;
                        }
                    }
                    if (!b[a_want] && a[b_want])
                    {
                        auto locks = pi(a | b, a_want);
                        if (!B[(a | b).to_ulong()][a_want])
                        {
                            state.emplace_back(locks);
                            B[(a | b).to_ulong()][a_want] = true;
                        }
                    }
                }
                if(unsafe)break;
            }
            if(unsafe)break;
            
        }
        
        if (!unsafe)
        {
            printf("SAFE\n");
        }      
        
    }
}



Measured memory_bytes: 3292