#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int h, w;
char c[30][30];

int main() {
    cin >> h >> w;
    rep(i,h) rep(j,w) cin >> c[i][j];
    int ans = 0;
    rep(i,h) rep(j,w) rep(k,h) rep(l,w) {
        if (c[i][j] == '.' || c[k][l] == '.') continue;
        ans = max(ans, abs(k-i)+abs(l-j));
    }
    cout << ans << endl;
}

