N = gets.to_i
U = []
R = []
D = []
L = []
N.times{
	s = gets.split
	x = s[0].to_i
	y = s[1].to_i
	case s[2]
	when "U"
		U << [x, y]
	when "R"
		R << [x, y]
	when "D"
		D << [x, y]
	when "L"
		L << [x, y]
	end
}
U.sort!
R.sort_by!{|i|[i[1], i[0]]}
D.sort!
L.sort_by!{|i|[i[1], i[0]]}
warn U.inspect
warn R.inspect
warn D.inspect
warn L.inspect
min = 2000001
U.each{|u|
	o = D.bsearch{|x|(u[0] - x[0]) * 2 + (u[1] <= x[1] ? 0 : -1)}
	if o
		if (o[1] - u[1]) * 5 < min
			min = (o[1] - u[1]) * 5
		end
	end
	i = R.bsearch_index{|x|x[1] >= u[1]}
	if i
		while i < R.size
			if (R[i][1] - u[1]) * 10 >= min
				break
			end
			if R[i][1] - u[1] == u[0] - R[i][0]
				min = (R[i][1] - u[1]) * 10
				break
			end
			i += 1
		end
	end
	i = L.bsearch_index{|x|x[1] >= u[1]}
	if i
		while i < L.size
			if (L[i][1] - u[1]) * 10 >= min
				break
			end
			if L[i][1] - u[1] == L[i][0] - u[0]
				min = (L[i][1] - u[1]) * 10
				break
			end
			i += 1
		end
	end
}
D.each{|d|
	i = R.bsearch_index{|x|x[1] > d[1]}
	unless i
		i = R.size
	end
	while i > 0
		i -= 1
		if (d[1] - R[i][1]) * 10 > min
			break
		end
		if d[1] - R[i][1] == d[0] - R[i][0]
			min = (d[1] - R[i][1]) * 10
			break
		end
	end
	i = L.bsearch_index{|x|x[1] >= d[1]}
	unless i
		i = L.size
	end
	while i > 0
		i -= 1
		if (d[1] - L[i][1]) * 10 > min
			break
		end
		if d[1] - L[i][1] == L[i][0] - d[0]
			min = (d[1] - L[i][1]) * 10
			break
		end
	end
}
R.each{|r|
	o = L.bsearch{|x|(r[1] - x[1]) * 2 + (r[0] <= x[0] ? 0 : -1)}
	if o
		if (o[0] - r[0]) * 5 < min
			min = (o[0] - r[0]) * 5
		end
	end
}

if min > 2000000
	min = "SAFE"
end
puts min
