#include<bits/stdc++.h>
using namespace std;
int W,H,sx,sy,ex,ey,xxx,yyy,fz[4][2] = {{-1,0},{0,-1},{1,0},{0,1}},ans;
char a[101][101];
bool f;//标记第1个C是否被找到
struct node{
int x,y,ls,fxx,fxy;//ls表示镜子个数,fxx和fxy均表示方向
};
queue<node> q;
void bfs()
{
q.push({sx,sy,0,0,0});
a[sx][sy] = '*';
while(!q.empty())
{
node head = q.front();
q.pop();
for(int i = 0;i < 4;i++)
{
xxx = head.x + fz[i][0];
yyy = head.y + fz[i][1];
if(xxx > 0 && xxx <= H && yyy > 0 && yyy <= W && a[xxx][yyy] != '*')
{
f = 0;
a[xxx][yyy] = '*';
if((head.fxx == 0 && head.fxy == 0)|| (head.fxx == fz[i][0] && head.fxy == fz[i][1])) q.push({xxx,yyy,head.ls,fz[i][0],fz[i][1]});
else f=1,q.push({xxx,yyy,head.ls + 1,fz[i][0],fz[i][1]});
if(f)a[xxx][yyy]='a';
if(xxx == ex && yyy == ey)
{
ans = head.ls;
return;
}
}
}
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> W >> H;
for(int i = 1;i <= H;i++) for(int j = 1;j <= W;j++)
{
cin >> a[i][j];
if(a[i][j] == 'C')
{
if(!f) sx = i,sy = j,f = 1;
else ex = i,ey = j;
}
}
for(int i = 1;i <= H;i++)
{
for(int j = 1;j <= W;j++)cout<<a[i][j];
cout<<endl;
}
bfs();
cout << ans;
return 0;
}
求各位神犇救救我orz