#include <iostream>
#include <vector>
#include <string>

using namespace std;

bool fail() {
    cout << "UNSAFE" << endl;
    return true;
}

bool solve() {
    int N;
    cin >> N;
    if (N == 0) return false;

    string S;
    cin >> S;

    vector<vector<bool>> dp(1 << 10, vector<bool>(10, false));
    int bit = 0;
    for (char c : S) {
        if (c == 'u') {
            bit = 0;
        } else {
            int ci = c - '0';
            int b = 1 << ci;
            if ((b & bit) != 0) return fail();

            dp[bit][ci] = true;
            bit |= (1 << ci);
        }
    }

    for (int A = 0; A < (1 << 10); ++A) {
        for (int B = 0; B < 10; ++B) {
            if (!dp[A][B]) continue;

            for (int C = 0; C < (1 << 10); ++C) {
                if ((A & C) || !((C >> B) & 1)) continue;

                for (int D = 0; D < 10; ++D) {
                    if (!dp[C][D]) continue;
                    dp[A | C][D] = true;
                }
            }
        }
    }

    for (int A = 0; A < (1 << 10); ++A) {
        for (int B = 0; B < 10; ++B) {
            if (!dp[A][B]) continue;

            for (int C = 0; C < (1 << 10); ++C) {
                if (A & C) continue;
                for (int D = 0; D < 10; ++D) {
                    if (!dp[C][D]) continue;

                    if (((A >> D) & 1) && ((C >> B) & 1)) {
                        return fail();
                    }
                }
            }
        }
    }

    cout << "SAFE" << endl;
    return true;
}

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