#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int h, w;
  cin >> h >> w;
  char s[22][22];
  for (int i = 1; i <= h; ++i)
    for (int j = 1; j <= w; ++j) cin >> s[i][j];
  for (int i = 1; i <= w; ++i) s[0][i] = s[h + 1][i] = '#';
  for (int i = 1; i <= h; ++i) s[i][0] = s[i][w + 1] = '#';
  const int INF = 1000;
  int dp[22][22][22][22];
  for (int i = 1; i <= h; ++i)
    for (int j = 1; j <= w; ++j)
      for (int k = 1; k <= h; ++k)
        for (int l = 1; l <= w; ++l) dp[i][j][k][l] = INF;
  for (int i = 1; i <= h; ++i)
    for (int j = 1; j <= w; ++j)
      if (s[i][j] == '.') {
        if (s[i - 1][j] == '.') dp[i - 1][j][i][j] = dp[i][j][i - 1][j] = 1;
        if (s[i + 1][j] == '.') dp[i + 1][j][i][j] = dp[i][j][i + 1][j] = 1;
        if (s[i][j - 1] == '.') dp[i][j - 1][i][j] = dp[i][j][i][j - 1] = 1;
        if (s[i][j + 1] == '.') dp[i][j + 1][i][j] = dp[i][j][i][j + 1] = 1;
      }
  for (int m = 1; m <= h; ++m)
    for (int n = 1; n <= w; ++n)
      for (int i = 1; i <= h; ++i)
        for (int j = 1; j <= w; ++j)
          for (int k = 1; k <= h; ++k)
            for (int l = 1; l <= w; ++l)
              dp[i][j][k][l] =
                  min(dp[i][j][k][l], dp[i][j][m][n] + dp[m][n][k][l]);
  int mx = 0;
  for (int i = 1; i <= h; ++i)
    for (int j = 1; j <= w; ++j)
      for (int k = 1; k <= h; ++k)
        for (int l = 1; l <= w; ++l)
          if (dp[i][j][k][l] != INF) mx = max(mx, dp[i][j][k][l]);
  cout << mx << endl;
  return 0;
}
