#include <bits/stdc++.h>
using namespace std;
int h, w, dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
vector<string> maze;
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    maze.push_back(s);
  }
  int output = 0;
  for (int sx = 0; sx < h - 1; sx++) {
    for (int sy = 0; sy < w - 1; sy++) {
      for (int gx = h - 1; gx >= 0; gx--) {
        for (int gy = w - 1; gy >= 0; gy--) {
          if (maze[sx][sy] == '#' || maze[gx][gy] == '#') continue;
          queue<pair<int, int>> que;
          vector<vector<int>> ans(h, vector<int>(w, -1));
          ans[sx][sy] = 0;
          que.push({sx, sy});
          while (!que.empty()) {
            int x = que.front().first, y = que.front().second;
            que.pop();
            for (int i = 0; i < 4; i++) {
              int nx = x + dx[i], ny = y + dy[i];
              if (nx < 0 || nx > h - 1 || ny < 0 || ny > w - 1 ||
                  maze[nx][ny] == '#' || ans[nx][ny] != -1)
                continue;
              que.push({nx, ny});
              ans[nx][ny] = ans[x][y] + 1;
            }
          }
          output = max(output, ans[gx][gy]);
        }
      }
    }
  }
  cout << output << endl;
  return 0;
}
