#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("Rj.in");
ofstream fout("Rj.out");
const int NMAX=105;
const int di[]={-1,-1,0,1,1,1,0,-1};
const int dj[]={0,1,1,1,0,-1,-1,-1};
struct coada
{
int lin,col;
}ro[100000],ju[100000];
void citire(int &n,int &m,int a[NMAX][NMAX],int b[NMAX][NMAX] )
{
int i,j;
char g;
fin>>n>>m; fin.get();
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
fin.get(g);
if(g=='X')
{
a[i][j]=-1;
b[i][j]=-1;
}
else
{
if(g==' ')
{
a[i][j]==0;
b[i][j]==0;
}
else
{
if(g=='J')
{
ju[1].lin=i;
ju[1].col=j;
a[i][j]=-1;
b[i][j]=1;
}
else
{
ro[1].lin=i;
ro[1].col=j;
a[i][j]=1;
b[i][j]=-1;
}
}
}
}
fin.get();
}
}
void bordare(int x[NMAX][NMAX],int n,int m)
{
for(int i=0;i<=n+1;i++)
x[i][0]=x[i][m+1]=-1;
for(int j=0;j<=m+1;j++)
x[0][j]=x[n+1][j]=-1;
}
void Lee(coada x[],int y[NMAX][NMAX])
{
int p=1,u=1,inou,jnou;
while(p<=u)
{
for(int k=0;k<8;k++)
{
inou=x[p].lin+di[k];
jnou=x[p].col+dj[k];
if(y[inou][jnou]==0)
{
u++;
x[u].lin=inou;
x[u].col=jnou;
y[inou][jnou]=y[x[p].lin][x[p].col]+1;
}
}
p++;
}
}
void afisare(int n,int m,int a[NMAX][NMAX],int b[NMAX][NMAX])
{
int mini[4];
mini[1]=NMAX*NMAX+5;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(a[i][j]>=1)
{
if(a[i][j]==b[i][j] && a[i][j]<mini[1])
{
mini[1]=a[i][j];
mini[2]=i;
mini[3]=j;
}
}
}
}
fout<<mini[1]<<" "<<mini[2]<<" "<<mini[3];
}
int main()
{
int n,m,a[NMAX][NMAX],b[NMAX][NMAX],i,j;
citire(n,m,a,b);
bordare(a,n,m);
bordare(b,n,m);
Lee(ro,a);
Lee(ju,b);
/*for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
cout<<b[i][j]<<" ";
cout<<"\n";
}*/
afisare(n,m,a,b);
return 0;
}