#include <bits/stdc++.h>
using namespace std;
int maze[25][25] = {};
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, -1, 0, 1};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    string str;
    cin >> str;
    for (int j = 0; j < w; j++) {
      if (str[j] == '.') maze[i + 1][j + 1] = 1;
    }
  }
  int ans = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      int dis[25][25] = {};
      memset(dis, -1, sizeof(dis));
      queue<int> qx, qy;
      qx.push(i), qy.push(j);
      dis[i][j] = 0;
      while (!qx.empty()) {
        int x = qx.front();
        qx.pop();
        int y = qy.front();
        qy.pop();
        ans = max(ans, dis[x][y]);
        for (int d = 0; d < 4; d++) {
          int xx = x + dx[d];
          int yy = y + dy[d];
          if (maze[xx][yy] && dis[xx][yy] == -1) {
            dis[xx][yy] = dis[x][y] + 1;
            qx.push(xx), qy.push(yy);
          }
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
