#include <bits/stdc++.h>
const int INF = 1e9 + 7;
using namespace std;
int bfs(vector<vector<char>> &s, int st_h, int st_w, int ed_h, int ed_w) {
  queue<pair<int, int>> que;
  queue<int> score;
  que.push(make_pair(st_h, st_w));
  score.push(0);
  int res = INT_MAX;
  bool goal = false;
  pair<int, int> dt[4] = {make_pair(-1, 0), make_pair(0, -1), make_pair(1, 0),
                          make_pair(0, 1)};
  vector<vector<int>> memo(s.size(), vector<int>(s[0].size(), 0));
  while (!que.empty()) {
    pair<int, int> pt = que.front();
    int now_score = score.front();
    que.pop();
    score.pop();
    memo[pt.first][pt.second] = 1;
    if (pt.first == ed_h && pt.second == ed_w) {
      res = min(res, now_score);
      goal = true;
      break;
    }
    for (int i = 0; i < 4; i++) {
      int new_h = pt.first + dt[i].first;
      int new_w = pt.second + dt[i].second;
      if (new_h < 0 || new_h >= s.size() || new_w < 0 || new_w >= s[0].size())
        continue;
      if (s[new_h][new_w] == '.' && memo[new_h][new_w] == 0) {
        que.push(make_pair(new_h, new_w));
        score.push(now_score + 1);
      }
    }
  }
  if (goal)
    return res;
  else
    return -1;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) cin >> s[i][j];
  int res = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      for (int k = 0; k < h; k++)
        for (int l = 0; l < w; l++)
          if (s[i][j] == '.' && s[k][l] == '.') {
            int ret = max(res, bfs(s, i, j, k, l));
            if (ret == -1)
              continue;
            else
              res = max(res, ret);
          }
  cout << res << endl;
  return 0;
}
