import Foundation
class queue{
var enq = [Int]()
var deq = [Int]()
var count: Int{
return enq.count + deq.count
}
func push(_ a:Int){
enq.append(a)
}
func pop()->Int{
if deq.count == 0{
deq = enq.reversed()
enq.removeAll()
}
if deq.count == 0{
return -1
}
return deq.popLast()!
}
}
let input = readLine()!.split(separator: " ").map{Int(String($0))!}
let N = input[0]
let M = input[1]
var snakeLadder = Array(repeating: 0, count: 100)
var visitCount = Array(repeating: 0, count: 100)
for _ in 0..<(N+M){
let input = readLine()!.split(separator: " ").map{Int(String($0))!}
snakeLadder[input[0]-1] = input[1] - 1
}
var q = queue()
q.push(0)
while q.count != 0 {
let this = q.pop()
for i in 1...6{
if this+i >= 100{
break;
}
let whereWeGo = snakeLadder[this+i] == 0 ? this+i :snakeLadder[this+i]
if visitCount[whereWeGo] == 0 {
visitCount[whereWeGo] = visitCount[this] + 1
q.push(whereWeGo)
}
}
}
print(visitCount[99])
왜 초록색이 생겼지요?