/**
 *    author:  orzvanh14 ( Độc cô cầu đặc )
 *    created: 23.12.2022 10:08:02
 *    too lazy to update time
**/
// i wants to take ioi
//binhtinhtutinkhongcaycunhungmotkhikhongcontutinnualatuyetvong
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define nn "\n"
#define pi pair<int, int>
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define eb emplace_back
#define pb push_back
#define TASK " "

#define ms(a, x) memset(a, x, sizeof(a))
#define all(a) a.begin(), a.end()
#define All(a, n) a + 1, a + 1 + n

#define LOG 19


const int INF = 1e18;
const int mod = 1e9+7;
const int N = 500  + 5;
int MOD = 998244353;
int bit[200000];
int r, c, t;
char a[N][N];
int sr = -1, sc, st, er, ec;
int d[N][N][4];
bool vis[N][N][4];
int sx[] = {0, 0, 1, -1};
int sy[] = {1, -1, 0, 0};
bool oki(int x, int y) {
    return (x >= 1 && x <= r && y >= 1 && y <= c && a[x][y] != '#');
}
bool ok(int x, int y, int st) {
    if(st == 0) return oki(x, y) && a[x][y] != 'E';
    if(st == 1) return oki(x, y) && oki(x, y - 1);
    if(st == 2) return oki(x, y) && oki(x - 1, y);
    return false;
}
void nhap(){
    
}

void bfs(){

		if(r == 0 && c == 0) return;
		int sr = -1;
		queue<tuple<int, int, int>> q;
		for(int i = 1; i <= r; i++){
			for(int j = 1; j <= c; j++){
				cin >> a[i][j];
				for(int k = 0; k < 3; k++){
                	vis[i][j][k] = false;
                	d[i][j][k] = 0;
            	}
				if(a[i][j] == 'X'){
                	if(sr == -1){
                    	sr = i; sc = j; st = 0;
                	}
                	else{
                    	if(i == sr) st = 1; 
                    	else st = 2; 
                    	sr = i; sc = j;
                	}
            	} 
            	else if(a[i][j] == 'O'){
                	er = i; ec = j;
            	}
			}
		}
		q.push({sr, sc, st});
		vis[sr][sc][st] = true;
	    d[sr][sc][st] = 0;
	    while(!q.empty()){
        	auto [x, y, tt] = q.front(); q.pop();
        	if(tt == 0 && x == er && y == ec){
            	cout << d[x][y][tt] << nn;
            	return;
        	}
        	int cx, cy, cst;
        	for(int i = 0; i < 4; i++){
            	if(tt == 0){ 
                	if(i == 0){ 
                		cx = x; cy = y - 1; cst = 1; 
                	}
                	else if(i == 1){ 
                		cx = x; cy = y + 2; cst = 1; 
                	}
                	else if(i == 2){ 
                		cx = x - 1; cy = y; cst = 2;
                	}
             		else{ 
             			cx = x + 2; cy = y; cst = 2; 
             		}
            	} 
            	else if(tt == 1){ 
                	if(i == 0){ 
                		cx = x; cy = y - 2; cst = 0; 
                	}
                	else if(i == 1){ 
                		cx = x; cy = y + 1; cst = 0; 
                	}
                	else if(i == 2){ 
                		cx = x - 1; cy = y; cst = 1; 
                	}
                	else{ 
                		cx = x + 1; cy = y; cst = 1; 
                	}
            	} 
            	else{ 
                	if(i == 0){ 
                		cx = x; cy = y - 1; cst = 2; 
                	}
               	 	else if(i == 1){ 
               	 		cx = x; cy = y + 1; cst = 2; 
               	 	}
                	else if(i == 2){ 
                		cx = x - 2; cy = y; cst = 0; 
                	}
                	else{ 
                		cx = x + 1; cy = y; cst = 0;
                	}
            	}
            	if(ok(cx, cy, cst) && !vis[cx][cy][cst]){
                	d[cx][cy][cst] = d[x][y][tt] + 1;
                	vis[cx][cy][cst] = 1;
                	q.push({cx, cy, cst});
            	}
        	}
    	}
    	cout << "Impossible" << nn;
		
	
}
signed main() {
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    while(cin >> r >> c){
    	bfs();
    }
	return 0;

}
