#include<bits/stdc++.h>
using namespace std;
using field=array<array<int,11>,11>;
int dx4[4]={1,-1,0,0};
int dy4[4]={0,0,1,-1};
bool ins(int i,int j){
return (0<=i && i<11 && 0<=j && j<11);
}
field inif;
int escape(int i,int j,int clk,field &a){
if(a[i][j]<=clk){return -1;}
field fie=inif;
queue<pair<int,int>> qq;
qq.push({i,j});
fie[i][j]=clk;
while(!qq.empty()){
auto od=qq.front(); qq.pop();
for(int k=0;k<4;k++){
int x=od.first+dx4[k];
int y=od.second+dy4[k];
if(!ins(x,y)){continue;}
int tt=fie[od.first][od.second]+1;
if(fie[x][y]>5e8 && tt<a[x][y]){
fie[x][y]=tt;
qq.push({x,y});
}
}
}
int res=1e9;
for(int i=0;i<11;i++){
res=min(res,fie[i][0]);
res=min(res,fie[i][10]);
res=min(res,fie[0][i]);
res=min(res,fie[10][i]);
}
if(res>5e8){res=-1;}
return res;
}
int main(){
for(int i=0;i<11;i++){
for(int j=0;j<11;j++){
inif[i][j]=1e9;
}
}
ios::sync_with_stdio(false);
cin.tie(nullptr);
field og=inif;
vector<pair<int,int>> vp;
queue<pair<int,int>> qq;
for(int i=0;i<11;i++){
for(int j=0;j<11;j++){
string s;
cin >> s;
if(s=="#"){og[i][j]=1e9;}
if(s=="P"){og[i][j]=1e9; vp.push_back({i,j});}
if(s=="F"){og[i][j]=0; qq.push({i,j});}
}
}
while(!qq.empty()){
auto od=qq.front(); qq.pop();
for(int i=0;i<4;i++){
int x=od.first+dx4[i];
int y=od.second+dy4[i];
if(!ins(x,y)){continue;}
if(og[x][y]>5e8){
og[x][y]=og[od.first][od.second]+1;
qq.push({x,y});
}
}
}
// for(auto &nx : og){
// for(auto &ny : nx){
// cout << ny << " ";
// }cout << "\n";
// }
int res=0;
do{
int cres=0;
int clk=0;
for(auto &nx : vp){
int cc=escape(nx.first,nx.second,clk,og);
// cout << cc << "\n";
if(cc<0){break;}
clk=(cc+1);
cres++;
}
res=max(res,cres);
}while(next_permutation(vp.begin(),vp.end()));
cout << res << "\n";
return 0;
}