import java.util.*;


public class Karel {
	public static class Tuple {
		public int state = 0;
		public int heading = 0;
		public int x = 0;
		public int y = 0;
		
		Tuple() {
			
		}
		
		Tuple(int x, int y, int state, int heading) {
			this.state = state;
			this.x = x;
			this.y = y;
			this.heading = heading;
		}
		
		@Override
		public boolean equals(Object o) {
			if(o instanceof Tuple) {
				Tuple t = (Tuple) o;
				return t.state == this.state
						&& t.x == this.x
						&& t.y == this.y
						&& t.heading == this.heading;
			}
			return false;
		}
		
		@Override
		public int hashCode() {
			int h = 1;
			h += 7 * state;
			h += 11 * x;
			h += 3 * y;
			h += 31 * heading;
			return h;
		}
		
		@Override
		public String toString() {
			return "X: " +x+ ", Y:" +y+ " , Head: " +heading+ " , State:" +state;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int row = sc.nextInt();
			int col = sc.nextInt();
			sc.nextLine();
			char[][] map = new char[row][col];
			for(int i = 0; i < row; i++) {
				String line = sc.nextLine();
				map[i] = line.toCharArray();
			}
			int len = sc.nextInt();
			sc.nextLine();
			char[] program = new char[len];
			program = sc.nextLine().toCharArray();
			int result = solve(map, program);
			System.out.println(result == -1 ? "OK" : result);
		}
	}
	
	static int solve(char[][] map, char[] program) {
		Set<Tuple> path;
		int count = 0;
		int solution = 0;
		for(int i = 0; i < map.length; i++) {
			char[] row = map[i];
			for(int j = 0; j < row.length; j++) {
				char cell = row[j];
				if(cell == 'E' || cell  == '.') {
					count++;
					path = new HashSet<Tuple>();
					Tuple state = new Tuple(j,i,0,0);
					while(true) {
						//System.out.println(state);
						if(isExit(map, state.x, state.y)) {
							solution++;
							break;
						}
						if(path.contains(state)) break;
						else path.add(state);
						state = makeStep(map, program, state);
					}
					//System.out.println("----------------");
				}
			}
		}
		if(count == solution) return -1; // OK
		else return solution;
	}
	
	static boolean isExit(char[][] map, int x, int y) {
		return map[y][x] == 'E';
	}
	
	static Tuple makeStep(char[][] map, char[] program, Tuple state) {
		Tuple ret = new Tuple();
		int x = state.x;
		int y = state.y;
		int heading = state.heading;
		int s = state.state;
		//System.out.println("-"+s);
		char command = program[s];
		s++;
		s %= program.length;
		//System.out.println("-"+s);
		switch(command) {
		case 'S':
			char nextPlace = getPosition(map, x, y, heading);
			if(nextPlace == '.' || nextPlace == 'E') {
				switch(heading) {
				case 0: y--; break;
				case 1: x++; break;
				case 2: y++; break;
				case 3: x--; break;
				}
			} 
			break;
		case 'L':
			heading--;
			if(heading < 0) heading = 3;
			break;
		case 'R':
			heading++;
			heading %= 4;
			break;
		}
		ret.x = x;
		ret.y = y;
		ret.heading = heading;
		ret.state = s;
		
		return ret;
	}
	
	static char getPosition(char[][] map, int x, int y, int heading) {
		switch(heading) {
		case 0: y--; break;
		case 1: x++; break;
		case 2: y++; break;
		case 3: x--; break;
		}
		int h = map.length;
		int w = map[0].length;
		if(x < 0 || y < 0 || x >= w || y >= h) return 'X';
		return map[y][x];
	}
}
