#include <bits/stdc++.h>
using namespace std;
using pi = pair<int, int>;
signed main() {
  int h, w;
  cin >> h >> w;
  vector<vector<bool>> maze(h, vector<bool>(w, false));
  for (int i = 0; i < h; ++i) {
    string s;
    cin >> s;
    for (int j = 0; j < w; ++j)
      if (s[j] == '.') maze[i][j] = true;
  }
  int res = 0;
  for (int srcy = 0; srcy < h; ++srcy)
    for (int srcx = 0; srcx < w; ++srcx) {
      if (!maze[srcy][srcx]) continue;
      queue<pair<pi, int>> que;
      que.push(make_pair(pi(srcy, srcx), 0));
      vector<vector<bool>> vis(h, vector<bool>(w, false));
      vector<vector<int>> cost(h, vector<int>(w, 1e7));
      while (!que.empty()) {
        pair<pi, int> q = que.front();
        que.pop();
        int &cury = q.first.first, &curx = q.first.second;
        assert(maze[cury][curx]);
        vis[cury][curx] = true;
        cost[cury][curx] = min(cost[cury][curx], q.second);
        if (cury - 1 >= 0 && maze[cury - 1][curx] && !vis[cury - 1][curx])
          que.push(make_pair(pi(cury - 1, curx), q.second + 1));
        if (cury + 1 < h && maze[cury + 1][curx] && !vis[cury + 1][curx])
          que.push(make_pair(pi(cury + 1, curx), q.second + 1));
        if (curx - 1 >= 0 && maze[cury][curx - 1] && !vis[cury][curx - 1])
          que.push(make_pair(pi(cury, curx - 1), q.second + 1));
        if (curx + 1 < w && maze[cury][curx + 1] && !vis[cury][curx + 1])
          que.push(make_pair(pi(cury, curx + 1), q.second + 1));
      }
      for (int i = 0; i < h; ++i)
        for (int j = 0; j < w; ++j)
          if (maze[i][j]) res = max(res, cost[i][j]);
    }
  cout << res;
}
