#include <fstream>
#include <queue>
#define Nmax 101
using namespace std;
ifstream cin ("rj.in");
ofstream cout ("rj.out");
int b[Nmax][Nmax],c[Nmax][Nmax],n,m;
short di[]={-1,-1,-1,0,1,1,1,0};
short dj[]={-1,0,1,1,1,0,-1,-1};
struct cordonates
{
int row;
int col;
};
cordonates rom,jul;
void read_and_optimise()
{
string ch;
cin >> n >> m;
getline(cin,ch);
for(int i = 1 ; i <= n ; ++i){
getline(cin,ch);
for(int j = 0 ; j < m ; ++j)
{
if(ch[j]=='R') rom.row=i , rom.col=j+1;
else if(ch[j]=='J') jul.row=i , jul.col=j+1;
else if(ch[j]=='X') b[i][j+1]=c[i][j+1]=-1;
}
}
}
bool inside(int i,int j)
{
return i>=1 && j<=m && j>=1 && i<=n;
}
void Lee(int i,int j,int mat[Nmax][Nmax])
{
queue<pair<int,int>>q;
mat[i][j]=1;
q.push(make_pair(i,j));
while(!q.empty())
{
int ii=q.front().first;
int jj=q.front().second;
q.pop();
for(int k = 0 ; k <= 7 ; ++k)
{
int i_nou=ii+di[k];
int j_nou=jj+dj[k];
if(!mat[i_nou][j_nou] && inside(i_nou,j_nou))
{
mat[i_nou][j_nou]=1+mat[ii][jj];
q.push(make_pair(i_nou,j_nou));
}
}
}
}
void solve()
{
int tmin=1000;
cordonates ans;
Lee(rom.row,rom.col,b);
Lee(jul.row,jul.col,c);
for(int i = 1 ; i <= n; ++i)
for(int j = 1; j <= m ; ++j)
if(b[i][j]==c[i][j] && b[i][j]<tmin && b[i][j]>0) tmin=b[i][j],ans.row=i,ans.col=j;
cout<<tmin<<" "<<ans.row<<' '<<ans.col<<' ';
}
int main()
{
read_and_optimise();
solve();
/*for(int i=1;i<=n;++i,cout<<endl)
for(int j=1;j<=m;j++) cout<<b[i][j]<<" ";*/
}