N x M grid. 'A' is you, 'M' is monster, '.' is floor, '#' is wall. You and monsters move simultaneously each second ( directions). Monsters move to catch you.
Find a path to any boundary cell where you escape before monsters catch you.
This is BFS, but with a twist. What is different from Labyrinth? You have multiple entities moving at once. The monsters also move on each time step. You need to know whether a monster can reach a cell before you do. Multi-source BFS from all monsters at once computes the earliest monster arrival time at every cell.