#include <bits/stdc++.h>
using namespace std ;
int n , m ;
char a[500][500] ;
bool p[500][500] ;
int f[500][500] ;
queue <int> qx ;
queue <int > qy ;
int dx[] = { 0 , 1 , 0 , -1 , 0 } ;
int dy[] = { 0 , 0 , 1 , 0 , -1 } ;
int xx , yy , fy , fx ;
void bfs () ;
int main ( ){
cin >> n >> m ;
for ( int i = 1 ; i <= n ; ++i ){
for ( int j = 1 ; j <= m ; ++j ){
cin >> a[i][j] ;
if ( a[i][j] == '@' ){
xx= i ;
yy = j ;
}
if ( a[i][j] == '=' ){
fx = i ;
fy = j ;
}
}
}
qx.push ( xx ) ;
qy.push ( yy ) ;
bfs( ) ;
return 0 ;
}
void bfs( ) {
while ( qx.size ( ) ){
int x = qx.front ( ) ;
int y = qy.front ( ) ;
qx.pop ( ) ;
qy.pop ( ) ;
if ( a[x][y] >= 'A' && a[x][y] <= 'Z' ){
int ff = 0 ;
char s = a[x][y] ;
for ( int i = 1 ; i<= n ; ++i ){
if ( ff ) break ;
for ( int j = 1 ; j <= m ; ++j ){
if ( (i == x && j == y ) || a[i][j] != s ) continue ;
else {
f[i][j] = f[x][y] ;
x = i ;
y = j ;
ff = 1 ;
break ;
}
}
}
}
for ( int i = 1 ;i <= 4 ; ++i ){
int xx = x + dx[i] ;
int yy = y + dy[i] ;
if ( xx >= 1 && xx <= n && yy >= 1 && yy <= m && a[xx][yy] != '#'){
if ( p[xx][yy] == 0 ){
p[xx][yy] = 1 ;
f[xx][yy] = f[x][y] + 1 ;
qx.push ( xx ) ;
qy.push ( yy ) ;
if ( xx == fx && yy == fy ){
cout << x << " " << y << endl ;
cout << f[xx][yy] ;
return ;
}
}
}
}
}
}