/**
  * @brief atcoder
  * @author yao
  */
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <climits>
#define ft first
#define sd second
#ifdef DBG
#   define dbg_pri(x...) fprintf(stderr,x)
#else
#   define dbg_pri(x...) 0
#   define NDEBUG
#endif //DBG
#include <cassert>

typedef unsigned int uint;
typedef long long int lli;
typedef unsigned long long int ulli;

#define N 262144

const char dn[] = "URDL";
std::pair<int,int> a[4][N];
int na[4];
std::pair<int,int> av[N], ah[N];
int nv, nh;
int ans = INT_MAX;

void find_ud()
{
    std::sort(av,av+nv);
    std::sort(ah,ah+nh);
    for(int i=0,j=0;i<nv;++i)
    {
        while(j<nh && ah[j] < av[i]) ++j;
        if(j==nh || av[i].ft != ah[j].ft) continue;
        ans = std::min(ans, (ah[j].sd-av[i].sd) * 5);
    }
}

void find_ur()
{
    for(int i=0;i<nv;++i)av[i] = {av[i].ft+av[i].sd, av[i].sd};
    for(int i=0;i<nh;++i)ah[i] = {ah[i].ft+ah[i].sd, ah[i].sd};
    std::sort(av,av+nv);
    std::sort(ah,ah+nh);
    for(int i=0,j=0;i<nv;++i)
    {
        while(j<nh && ah[j] < av[i]) ++j;
        if(j==nh || av[i].ft != ah[j].ft) continue;
        ans = std::min(ans, (ah[j].sd-av[i].sd) * 10);
    }
}

int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0;i<n;++i)
    {
        int x, y;
        char u;
        scanf("%d%d %c", &x, &y, &u);
        const char *p = strchr(dn,u);
        assert(p);
        int k = p - dn;
        a[k][na[k]++] = {x,y};
    }
    nv = na[0], nh = na[2];
    for(int i=0;i<nv;++i) av[i] = a[0][i];
    for(int i=0;i<nh;++i) ah[i] = a[2][i];
    find_ud();
    nv = na[1], nh = na[3];
    for(int i=0;i<nv;++i) av[i] = {a[1][i].sd,a[1][i].ft};
    for(int i=0;i<nh;++i) ah[i] = {a[3][i].sd,a[3][i].ft};
    find_ud();
    nv = na[0], nh = na[1];
    for(int i=0;i<nv;++i) av[i] = a[0][i];
    for(int i=0;i<nh;++i) ah[i] = a[1][i];
    find_ur();
    nv = na[0], nh = na[3];
    for(int i=0;i<nv;++i) av[i] = {-a[0][i].ft,a[0][i].sd};
    for(int i=0;i<nh;++i) ah[i] = {-a[3][i].ft,a[3][i].sd};
    find_ur();
    nv = na[2], nh = na[1];
    for(int i=0;i<nv;++i) av[i] = {a[2][i].ft,-a[2][i].sd};
    for(int i=0;i<nh;++i) ah[i] = {a[1][i].ft,-a[1][i].sd};
    find_ur();
    nv = na[2], nh = na[3];
    for(int i=0;i<nv;++i) av[i] = {-a[2][i].ft,-a[2][i].sd};
    for(int i=0;i<nh;++i) ah[i] = {-a[3][i].ft,-a[3][i].sd};
    find_ur();
    if(ans == INT_MAX) return puts("SAFE"), 0;
    printf("%d\n", ans);
    return 0;
}
