// Arup Guha
// 2/3/2015
// Solution to 2014 MCPC Problem F: The Maze Makers

import java.util.*;

public class f {

	public static int R;
	public static int C;
	public static int[][] grid;
	public static ArrayList[] graph;

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		R = stdin.nextInt();
		C = stdin.nextInt();

		// Go through cases.
		while (R != 0) {

			// Read in grid.
			grid = new int[R][C];
			for (int i=0; i<R; i++) {
				String line = stdin.next();
				for (int j=0;j<C; j++) {
					if (Character.isDigit(line.charAt(j)))
						grid[i][j] = line.charAt(j) - '0';
					else
						grid[i][j] = line.charAt(j) - 'A' + 10;
				}
			}

			// Make the underlying graph.
			formGraph();

			// Find the beginning and ending of the maze.
			int[] endNodes = getEndNodes();

			// Solve and print!
			System.out.println(solve(endNodes));

			// Get next case.
			R = stdin.nextInt();
			C = stdin.nextInt();
		}
	}

	public static void formGraph() {

		// Allocate space for the graph.
		graph = new ArrayList[R*C];
		for (int i=0; i<graph.length; i++)
			graph[i] = new ArrayList<Integer>();

		for (int i=0; i<graph.length; i++) {

			// These will be useful.
			int x = i/C, y = i%C, mask = 15 - grid[i/C][i%C];

			// Check each direction - add edge if necessary.
			if (((mask & 1) > 0) && y > 0) graph[i].add(i-1);
			if (((mask & 2) > 0) && x < R-1) graph[i].add(i+C);
			if (((mask & 4) > 0) && y < C-1) graph[i].add(i+1);
			if (((mask & 8) > 0) && x > 0) graph[i].add(i-C);
		}
	}

	public static int[] getEndNodes() {

		int[] res = new int[2];
		int index = 0;

		// Look down left wall.
		for (int i=0; i<R; i++)
			if (((15-grid[i][0]) & 1) > 0)
				res[index++] = C*i;

		// Right wall.
		for (int i=0; i<R; i++)
			if (((15-grid[i][C-1]) & 4) > 0)
				res[index++] = C*i + C - 1;

		// Top wall.
		for (int i=0; i<C; i++)
			if (((15-grid[0][i]) & 8) > 0)
				res[index++] = i;

		// Bottom wall.
		for (int i=0; i<C; i++)
			if (((15-grid[R-1][i]) & 2) > 0)
				res[index++] = (R-1)*C + i;

		return res;
	}

	public static String solve(int[] endNodes) {

		// Stores -1 if not visited, value of previous node if visited.
		int[] visited = new int[R*C];
		Arrays.fill(visited, -1);

		// Set up queue for bfs.
		LinkedList<Integer> q = new LinkedList<Integer>();
		q.offer(endNodes[0]);
		boolean multiplePaths = false;

		// Marks previous node as a ficticious one, so we think this node
		// is visited.
		visited[endNodes[0]] = R*C;

		// Run bfs.
		while (q.size() > 0) {

			int cur = q.poll();

			// Go through neighbors.
			for (int i=0; i<graph[cur].size(); i++) {
				int next = (Integer)graph[cur].get(i);

				// Never been here before.
				if (visited[next] == -1) {
					q.offer(next);
					visited[next] = cur;
				}

				// Oops, two ways to get here, so a cycle.
				else if (visited[next] != cur && visited[cur] != next)
					multiplePaths = true;
			}
		}

		// See if we got to the end node.
		if (visited[endNodes[1]] == -1) return "NO SOLUTION";

		// See if there was some node that wasn't reached.
		for (int i=0; i<graph.length; i++)
			if (visited[i] == -1)
				return "UNREACHABLE CELL";

		// Found a cycle...
		if (multiplePaths) return "MULTIPLE PATHS";

		// It's good!
		return "MAZE OK";
	}
}