public struct Deque { private var front: [T] = [] private var back: [T] = [] public var isEmpty: Bool { return front.isEmpty && back.isEmpty } public var count: Int { return front.count + back.count } public mutating func append(_ element: T) { back.append(element) } public mutating func prepend(_ element: T) { front.append(element) } public mutating func popFirst() -> T? { if front.isEmpty { front = back.reversed() back.removeAll() } return front.popLast() } public mutating func popLast() -> T? { if back.isEmpty { back = front.reversed() front.removeAll() } return back.popLast() } } if let input = readLine(), let nm = { let numList = input.split(separator : " ").compactMap({Int($0)}) return numList.count==2 ? numList : nil }() as [Int]? { let N = nm[0] let M = nm[1] var q: Deque<(Int, Int)> = Deque() var snake_ladder: [Int: Int] = Dictionary(uniqueKeysWithValues: zip(1...100, 1...100)) var visited: [Bool] = Array(repeating: false, count: 101) for _ in 0..