#include <bits/stdc++.h>
using namespace std;
int h, w;
vector<string> maze;
vector<vector<int>> dp;
int f(int i, int j) { return 23 * i + j; }
signed main() {
  cin >> h >> w;
  string s;
  for (int i = 0; i < h; ++i) {
    cin >> s;
    maze.push_back(s);
  }
  dp = vector<vector<int>>(23 * 23, vector<int>(23 * 23, INT_MAX));
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (maze[i][j] == '.') {
        if (i < h - 1 && maze[i + 1][j] == '.')
          dp[f(i, j)][f(i + 1, j)] = 1, dp[f(i + 1, j)][f(i, j)] = 1;
        if (j < w - 1 && maze[i][j + 1] == '.')
          dp[f(i, j)][f(i, j + 1)] = 1, dp[f(i, j + 1)][f(i, j)] = 1;
      }
    }
  }
  int maxi = 0;
  h = w = 23;
  for (int k = 0; k < h * w; k++) {
    for (int i = 0; i < h * w; i++) {
      for (int j = 0; j < h * w; j++) {
        if (dp[i][k] + dp[k][j] < dp[i][j] && dp[i][k] != INT_MAX &&
            dp[k][j] != INT_MAX) {
          dp[i][j] = dp[i][k] + dp[k][j];
          if (dp[i][j] != INT_MAX) maxi = max(maxi, dp[i][j]);
        }
      }
    }
  }
  cout << maxi << endl;
}
