from collections import deque dr = [0, 0, 1, -1] #우좌하상 dc = [1, -1, 0, 0] N, M = map(int,input().split()) mapp=[[] for i in range(N)] for i in range(N): temp = input() for j in range(M): if temp[j] =='R': r_red = i c_red = j if temp[j] =='B': r_blue = i c_blue = j if temp[j] =='O': r_exit = i c_exit = j mapp[i]=temp ############################## def bfs(mapp, visited, q_red, q_blue ): r_cur_red..