#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <cstring>
#include <unordered_map>
#include <iomanip>
#include <queue>
#include <map>
#include <sstream>
#include <stack>
#include <bitset>
#include <random>
using ll = long long;
using namespace std;
constexpr int nm = (1 << 9) + 10;
constexpr pair<int, int> dirs[] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
char a[20][20];
int t[20][20];
int f[nm];
int findCost(int t0, int u, int v) {
if (t[u][v] <= t0) return 1e9;
vector<vector<int>> t2(20, vector<int>(20, 1e9));
t2[u][v] = t0;
queue<pair<int, int>> q;
q.emplace(u, v);
while (q.size()) {
auto [i, j] = q.front();
q.pop();
if (i == 0 || i == 10 || j == 0 || j == 10) return t2[i][j] + 1;
for (auto [dx, dy]: dirs) {
int i2 = i + dx, j2 = j + dy;
if (i2 >= 0 && i2 < 11 && j2 >= 0 && j2 < 11 && t2[i2][j2] > t2[i][j] + 1 && t[i2][j2] > t2[i][j] + 1) {
t2[i2][j2] = t2[i][j] + 1;
q.emplace(i2, j2);
}
}
}
return 1e9;
}
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
vector<pair<int, int>> people;
vector<pair<int, int>> fire;
memset(t, 0x3f, sizeof(t));
queue<pair<int, int>> q;
for (int i = 0; i < 11; ++i) {
for (int j = 0; j < 11; ++j) {
cin >> a[i][j];
if (a[i][j] == 'P') people.emplace_back(i, j);
else if (a[i][j] == 'F') {
fire.emplace_back(i, j);
t[i][j] = 0;
q.emplace(i, j);
}
}
}
while (q.size()) {
auto [i, j] = q.front();
q.pop();
for (auto [dx, dy]: dirs) {
int i2 = i + dx, j2 = j + dy;
if (i2 >= 0 && i2 < 11 && j2 >= 0 && j2 < 11 && t[i2][j2] > t[i][j] + 1) {
t[i2][j2] = t[i][j] + 1;
q.emplace(i2, j2);
}
}
}
// for (int i = 0; i < 11; ++i) {
// for (int j = 0; j < 11; ++j) {
// cout << t[i][j] << " ";
// }
// cout << "\n";
// }
priority_queue<pair<int, int>> pq;
memset(f, 0x3f, sizeof(f));
f[0] = 0;
pq.emplace(0, 0);
int n = people.size();
int res = 0;
while (pq.size()) {
auto [fmask, mask] = pq.top();
pq.pop();
if (fmask != -f[mask]) continue;
// cout << mask << " " << f[mask] << "\n";
res = max(res, __builtin_popcount(mask));
for (int i = 0; i < n; ++i) {
if ((mask >> i) & 1) continue;
int cost = findCost(f[mask], people[i].first, people[i].second);
// cout << "try " << people[i].first << " " << people[i].second << " " << cost << "\n";
if (cost >= 1e9) continue;
int mask2 = mask | (1 << i);
if (f[mask2] > cost) {
f[mask2] = cost;
pq.emplace(-f[mask2], mask2);
}
}
}
cout << res << "\n";
}