gets
U=[]
R=[]
D=[]
L=[]
$<.map{*z,r=_1.split
eval r+"<<[%d,%d]"%z}
x=1e9
[[D,U,'[x,y,%d]'],[L,R,'[y,x,%d]'],[U,R,'[x+y,x-y,%d]'],[L,D,'[x+y,x-y,%d]'],[L,U,'[x-y,x+y,%d]'],[D,R,'[x-y,x+y,%d]']].map{|*a,e|s=t=p
[0,1].map{|i|a[i].map{|x,y|eval e%i}}.flatten(1).sort.map{_3==1?(s,t=_1,_2):s==_1&&x>_2-t&&(x=_2-t)}}
puts x<1e9?x*5:"SAFE"