fileprivate struct Scanner {
    private var elements = [String]()
    private var index = 0
    
    mutating func peek() -> String {
        while elements.count == index {
            elements = readLine()!.split(separator: " ").map(String.init)
            index = 0
        }
        return elements[index]
    }
    
    mutating func next() -> String {
        let value = peek()
        index += 1
        return value
    }
    
    mutating func nextInt() -> Int {
        return Int(next())!
    }
    
    mutating func nextDouble() -> Double {
        return Double(next())!
    }
}

func rotate(point: Point) -> Point {
    Point(x: -point.y, y: point.x)
}

func rotate(direction: String) -> String {
    switch direction {
    case "U": return "L"
    case "L": return "D"
    case "D": return "R"
    default: return "U"
    }
}

func flip(point: Point) -> Point {
    Point(x: point.x, y: -point.y)
}

func flip(direction: String) -> String {
    switch direction {
    case "U": return "D"
    case "D": return "U"
    default: return direction
    }
}

struct Point {
    let x: Int
    let y: Int
}

func main() {
    var scanner = Scanner()
    let N = scanner.nextInt()
    var P = [Point]()
    var U = [String]()
    
    for _ in 0 ..< N {
        let x = scanner.nextInt()
        let y = scanner.nextInt()
        P.append(Point(x: x, y: y))
        U.append(scanner.next())
    }
    
    func solve() -> Int {
        let I = (0 ..< N).sorted { P[$0].x > P[$1].x }
        var diag = [Int: Int]()
        var yoko = [Int: Int]()
        var answer = Int.max
        for i in I {
            if U[i] == "R", let value = diag[P[i].x - P[i].y] {
                answer = min(answer, (value - P[i].y) * 10)
            }
            if U[i] == "R", let value = yoko[P[i].y] {
                answer = min(answer, (value - P[i].x) * 5)
            }
            if U[i] == "D" {
                diag[P[i].x - P[i].y] = P[i].y
            }
            if U[i] == "L" {
                yoko[P[i].y] = P[i].x
            }
        }
        return answer
    }
    
    var answer = Int.max
    for _ in 0 ..< 4 {
        for _ in 0 ..< 2 {
            answer = min(answer, solve())
            
            for i in 0 ..< N {
                P[i] = flip(point: P[i])
                U[i] = flip(direction: U[i])
            }
        }
        for i in 0 ..< N {
            P[i] = rotate(point: P[i])
            U[i] = rotate(direction: U[i])
        }
    }
    if answer == Int.max {
        print("SAFE")
    } else {
        print(answer)
    }
}

main()
