N = gets.chomp.to_i
Planes = []
N.times{
  x, y, u = gets.chomp.split
  Planes.push [x.to_i, y.to_i, u]
}

#group_by_x = Planes.group_by{ |p| p[0] }
#group_by_y = Planes.group_by{ |p| p[1] }
group_by_u = Planes.group_by{ |p| p[2] }
group_by_u["U"] ||= []
group_by_u["D"] ||= []
group_by_u["R"] ||= []
group_by_u["L"] ||= []
#p group_by_u

collisions = []

group_by_u["U"].each{ |u|
  group_by_u["D"].each{ |d|
    if u[0] == d[0]
      collisions.push [u, d, (d[1] - u[1])/2]
    end
  }
}

group_by_u["R"].each{ |r|
  group_by_u["L"].each{ |l|
    if r[1] == l[1]
      collisions.push [r, l, (l[0] - r[0])/2]
    end
  }
}

group_by_u["U"].each{ |a|
  group_by_u["R"].each{ |b|
    if (a[0] - b[0]) == (b[1] - a[1])
      collisions.push [a, b, (a[0] - b[0])]
    end
  }
}

group_by_u["U"].each{ |a|
  group_by_u["L"].each{ |b|
    if (b[0] - a[0]) == (b[1] - a[1])
      collisions.push [a, b, (b[0] - a[0])]
    end
  }
}

group_by_u["D"].each{ |a|
  group_by_u["R"].each{ |b|
    if (a[0] - b[0]) == (a[1] - b[1])
      collisions.push [a, b, (a[0] - b[0])]
    end
  }
}

group_by_u["D"].each{ |a|
  group_by_u["L"].each{ |b|
    if (b[0] - a[0]) == (a[1] - b[1])
      collisions.push [a, b, (b[0] - a[0])]
    end
  }
}

collisions.select!{ |c| c[2] >= 0 }

#p collisions

if collisions.empty?
  puts "SAFE"
else
  puts collisions.sort{ |a, b| a[2] <=> b[2] }.last[2] * 10
end
