import Foundation func readInt2() -> (Int, Int) { let l = readLine()!.split(separator: " ").map{Int($0)!} return (l[0], l[1]) } func readLines(_ n: Int) -> [[Bool]] { return (0.. [Bool] in return readLine()!.split(separator: " ").map{$0 == "1"} } } let (H, W) = readInt2() var A = readLines(H) var dirc = [(-1, 0),(0, 1),(1, 0),(0, -1)] var ans = 0 for i in 0..= H || sucX < 0 || sucX >= W || !A[sucY][sucX] { continue } frontier.append((sucY, sucX)) } } } } print(ans)