from collections import deque
import sys; input=sys.stdin.readline
n, m = map(int, input().split())
arr = [list(input().strip()) for _ in range(n)]

def bfs():
    queue = deque()
    while queue:
        pass


