#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 10001

struct Info{
	Info(int arg_have_lock,int arg_next){
		have_lock = arg_have_lock;
		next = arg_next;
	}
	int have_lock,next;
};

int POW[11];
int length;
bool check[1024][10];
char buf[NUM];
vector<Info> V;


void func(){

	for(int i = 0; i < POW[10]; i++){
		for(int k = 0; k < 10; k++)check[i][k] = false;
	}

	scanf("%s",buf);

	int have_lock = 0,next;
	V.clear();

	for(int i = 0; i < length; i++){

		if(buf[i] == 'u'){

			have_lock = 0;

		}else{

			next = buf[i]-'0';

			if(have_lock & (POW[next])){
				printf("UNSAFE\n");
				return;
			}
			if(!check[have_lock][next]){
				V.push_back(Info(have_lock,next));
				check[have_lock][next] = true;
			}
			have_lock += POW[next];
		}
	}

	vector<Info> ADD;
	int new_have_lock,new_next;
	bool FLG;

	while(true){

		for(int i = 0; i < V.size(); i++){
			for(int k = 0; k < V.size(); k++){

				if(i == k || (V[i].have_lock & V[k].have_lock) != 0)continue;

				if((POW[V[i].next] & V[k].have_lock) != 0 && (POW[V[k].next] & V[i].have_lock) != 0){
					printf("UNSAFE\n");
					return;
				}

				FLG = false;

				if((POW[V[i].next] & V[k].have_lock) != 0 && (POW[V[k].next] & V[i].have_lock) == 0){

					new_next = V[k].next;
					FLG = true;

				}else if((POW[V[k].next] & V[i].have_lock) != 0 && (POW[V[i].next] & V[k].have_lock) == 0){

					new_next = V[i].next;
					FLG = true;
				}

				if(FLG){
					new_have_lock = V[i].have_lock|V[k].have_lock;
					if(!check[new_have_lock][new_next]){
						ADD.push_back(Info(new_have_lock,new_next));
						check[new_have_lock][new_next] = true;
					}
				}
			}
		}

		if(ADD.size() == 0)break;

		for(int i = 0; i < ADD.size(); i++){
			V.push_back(ADD[i]);
		}
		ADD.clear();
	}

	printf("SAFE\n");
}

int main(){

	for(int i = 0; i < 11; i++)POW[i] = pow(2,i);

	while(true){
		scanf("%d",&length);
		if(length == 0)break;

		func();
	}

	return 0;
}

