#include <bits/stdc++.h>
using namespace std;
vector<long long> d2dist(vector<vector<char>>& input, pair<int, int> start) {
  vector<vector<int>> dp(input.size() + 2,
                         vector<int>(input[0].size() + 2, 100000));
  start.first++;
  start.second++;
  dp[start.first][start.second] = 0;
  vector<long long> ret(3);
  for (int times1 = 0; times1 < (int)(input.size() * input[0].size()); times1++)
    for (int times2 = 0; times2 < (int)(input[0].size() * input.size());
         times2++) {
      for (int i = 1; i < input.size() + 1; i++) {
        for (int j = 1; j < input[0].size() + 1; j++) {
          if (input[i - 1][j - 1] == '.') {
            dp[i][j] = min({dp[i][j], dp[i - 1][j] + 1, dp[i + 1][j] + 1,
                            dp[i][j - 1] + 1, dp[i][j + 1] + 1});
            if (dp[i][j] >= 100000) continue;
            dp[i][j] > ret[2] ? ret[0] = i - 1, ret[1] = j - 1,
                                ret[2] = dp[i][j] : 1;
          }
        }
      }
    }
  return ret;
}
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> table(H, vector<char>(W));
  pair<int, int> start;
  for (int i = 0; i < (int)(H); i++)
    for (int j = 0; j < (int)(W); j++) {
      cin >> table[i][j];
      if (table[i][j] == '.') {
        start = {i, j};
      }
    }
  vector<long long> Max_from_zero;
  Max_from_zero = d2dist(table, {0, 0});
  vector<long long> ans =
      d2dist(table, {Max_from_zero.at(0), Max_from_zero.at(1)});
  cout << ans[2] << endl;
}
