#include <bits/stdc++.h>
// #ifndef ONLINE_JUDGE
// #include <debug.h>
// #else
// #define debug(...)
// #endif
#define GOOD_LUCK ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define all(v) v.begin(), v.end()
using namespace std;
int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
constexpr int MAX = 4e+3 + 1, INF = 2e+16, MOD = 1e+9 + 7, K = 31;
int n, m;
vector <string> v;
vector <vector <int>> col(MAX+2, vector <int>(MAX+2, 0));
void dfs(int ux, int uy, char c) {
col[ux][uy] = 1;
for (int z = 0; z < 4; z++) {
int ix = ux + dx[z], iy = uy + dy[z];
if (ix < 0 || iy < 0 || ix >= n || iy >= m) continue;
if (v[ix][iy] != c) continue;
if (col[ix][iy]) continue;
dfs(ix, iy, c);
}
}
void _() {
cin >> n >> m;
v.resize(n);
for (auto &i : v) cin >> i;
int a = 0, b=0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (v[i][j] == 'F' && !col[i][j]) {
dfs(i, j, 'F');
a++;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) col[i][j] = 0;
}
for (int i = 0; i < n; i++) {
for (int j= 0; j < m; j++) {
if (v[i][j] == 'R' && !col[i][j]) {
dfs(i, j, 'R');
b++;
}
}
}
if (v[0][0] == 'F') {
if (a == 2) cout << 3;
else if (b == 0) cout << 1;
else cout << 2;
}
else {
if (b == 2) cout << 3;
else if (a == 0) cout << 1;
else cout << 2;
}
}
signed main() {
GOOD_LUCK
int tests=1;
// cin >> tests;
for (int i=1; i <= tests; i++) {
_();
cout << endl;
}
return 0;
}