#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(kbrni,n)cout<<" "<<a[kbrni];cout<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define svecp(v) cout<<#v<<":";each(kbrni,v)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

vector<int> e[11][11];
vector<int> G[11];
int visit[11];

void dfs(int u,int& id,vvi& route,vi& hoge)
{
    visit[u] = id++;
    rep(i,len(G[u])){
        if(visit[G[u][i]] != -1 && visit[G[u][i]] <= visit[u]){
            vi ag;
            rep(j,len(hoge)){
                if(hoge[j] == G[u][i]){
                    for(;j<len(hoge);j++){
                        ag.pb(hoge[j]);
                    }
                }
            }
            ag.pb(u);
            route.pb(ag);
        }else{
            hoge.pb(u);
            dfs(G[u][i],id,route,hoge);
            hoge.pop_back();
        }
    }
}

int main()
{
    // cin.tie(0);
    // ios::sync_with_stdio(false);ccccc
    while(1){
        int n;
        cin >> n;
        if(n == 0){
            break;
        }
        string s;
        cin >> s;
        int kp = 0;
        bool end = false;
        rep(i,10){
            rep(j,10){
                e[i][j].clear();
            }
        }
        rep(i,10){
            G[i].clear();
            visit[i] = -1;
        }
        rep(i,len(s)){
            if(s[i] == 'u'){
                kp = 0;
            }else if(kp & (1 << (int)(s[i]-'0'))){
                cout << "UNSAFE\n";
                end = true;
                break;
            }else{
                kp |= (1 << (int)(s[i]-'0'));
            }
        }
        if(end){
            continue;
        }
        kp = 0;
        rep(i,len(s)-1){
            if(s[i] != 'u'){
                if(s[i+1] != 'u'){
                    int a = (int)(s[i]-'0'),b = (int)(s[i+1]-'0');
                    e[a][b].pb(kp);
                    kp |= (1 << (int)(s[i]-'0'));
                }
            }else{
                kp = 0;
            }
        }
        rep(i,10){
            rep(j,10){
                if(len(e[i][j])){
                    G[i].pb(j);
                }
            }
        }
        rep(i,10){
            if(visit[i] == -1){
                vvi route;
                vi hoge;
                int id = 0;
                dfs(i,id,route,hoge);
                // rep(i,len(route)){
                //     svec(route[i]);
                // }
                rep(j,len(route)){
                    int loop = len(route[j]);
                    vvi vec(loop);
                    rep(k,len(route[j])){
                        int a = route[j][k],b = route[j][(k+1)%loop];
                        vec[k] = e[a][b];
                        // if(len(vec[k])==0){
                        //     svec(route[j]);
                        //     cout << a << " " << b << "\n";
                        // }
                    }
                    set<int> dp[11];
                    dp[0].insert(0);
                    rep(j,loop){
                        each(k,dp[j]){
                            rep(l,len(vec[j])){
                                if(!(k & vec[j][l])){
                                    dp[j+1].insert(k|vec[j][l]);
                                }
                            }
                        }
                    }
                    if(len(dp[loop])){
                        cout << "UNSAFE\n";
                        end = true;
                        break;
                    }
                }
                if(end){
                    break;
                }
            }
        }
        if(!end){
            cout << "SAFE\n";
        }
    }
    return 0;
}



Measured memory_bytes: 3324