#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < (int)(H); i++) cin >> S[i];
  long long ans = 0;
  for (int i = 0; i < (int)(H); i++)
    for (int j = 0; j < (int)(W); j++)
      for (int k = 0; k < (int)(H); k++)
        for (int l = 0; l < (int)(W); l++) {
          pair<int, int> start = pair<int, int>(i, j),
                         goal = pair<int, int>(k, l);
          vector<vector<int>> dis(H, (vector<int>(W, -1)));
          dis[start.first][start.second] = 0;
          queue<pair<int, int>> que{};
          que.push(start);
          while (!que.empty()) {
            pair<int, int> p = que.front();
            que.pop();
            int y = p.first, x = p.second;
            if (p.first == goal.first && p.second == goal.second) break;
            if (x > 0 && W > 1) {
              int nx = x - 1, ny = y;
              if (S[ny][nx] == '.' && dis[ny][nx] == -1) {
                dis[ny][nx] = dis[y][x] + 1;
                que.push(pair<int, int>(ny, nx));
              }
            }
            if (x < W - 1) {
              int nx = x + 1, ny = y;
              if (S[ny][nx] == '.' && dis[ny][nx] == -1) {
                dis[ny][nx] = dis[y][x] + 1;
                que.push(pair<int, int>(ny, nx));
              }
            }
            if (y > 0 && H > 1) {
              int nx = x, ny = y - 1;
              if (S[ny][nx] == '.' && dis[ny][nx] == -1) {
                dis[ny][nx] = dis[y][x] + 1;
                que.push(pair<int, int>(ny, nx));
              }
            }
            if (y < H - 1) {
              int nx = x, ny = y + 1;
              if (S[ny][nx] == '.' && dis[ny][nx] == -1) {
                dis[ny][nx] = dis[y][x] + 1;
                que.push(pair<int, int>(ny, nx));
              }
            }
          }
          if (dis[goal.first][goal.second] == -1) continue;
          ans = max((long long)dis[goal.first][goal.second], ans);
        }
  cout << ans << endl;
}
