N=gets.to_i
U=[]
R=[]
D=[]
L=[]
N.times do
    x,y,u=gets.chomp.split(" ")
    x=x.to_i
    y=y.to_i
    if u == "U"
        U.push([x,y])
    elsif u == "R"
        R.push([x,y])
    elsif u == "D"
        D.push([x,y])
    else
        L.push([x,y])
    end
end
ret = 400000
U.each do |x,y|
    R.each do |a,b|
        if x-a==b-y && x-a>0
            r = (x-a)*10
            ret = r if r < ret
        end
    end
    L.each do |a,b|
        if a-x==b-y && a-x>0
            r = (a-x)*10
            ret = r if r < ret
        end
    end
    D.each do |a,b|
        if x==a && b > y
            r = (b-y)*5
            ret = r if r < ret
        end
    end
end
D.each do |x,y|
    R.each do |a,b|
        if x-a==y-b && x-a>0
            r = (x-a)*10
            ret = r if r < ret
        end
    end
    L.each do |a,b|
        if a-x==y-b && a-x>0
            r = (a-x)*10
            ret = r if r < ret
        end
    end
end
L.each do |x,y|
    R.each do |a,b|
        if y==b && a < x
            r = (x-a)*5
            ret = r if r < ret
        end
    end
end

if ret > 200000
    puts 'SAFE'
else
    puts ret
end
