#include <bits/stdc++.h>
using namespace std;
long long int h, w;
bool flag = false;
long long int solve(vector<vector<char>> &v, long long int start_x,
                    long long int start_y, long long int fin_x,
                    long long int fin_y, long long int x, long long int y,
                    vector<vector<int>> &dp, vector<vector<bool>> vis) {
  vis[x][y] = true;
  if (x == fin_x && y == fin_y) {
    flag = true;
    return 0;
  }
  if (dp[x][y] != -1) return dp[x][y];
  long long int d1(INT_MAX), d2(INT_MAX), d3(INT_MAX), d4(INT_MAX);
  if (x + 1 < h && v[x + 1][y] == '.' && !vis[x + 1][y])
    d1 = 1 + solve(v, start_x, start_y, fin_x, fin_y, x + 1, y, dp, vis);
  if (x - 1 >= 0 && v[x - 1][y] == '.' && !vis[x - 1][y])
    d2 = 1 + solve(v, start_x, start_y, fin_x, fin_y, x - 1, y, dp, vis);
  if (y + 1 < w && v[x][y + 1] == '.' && !vis[x][y + 1])
    d3 = 1 + solve(v, start_x, start_y, fin_x, fin_y, x, y + 1, dp, vis);
  if (y - 1 >= 0 && v[x][y - 1] == '.' && !vis[x][y - 1])
    d4 = 1 + solve(v, start_x, start_y, fin_x, fin_y, x, y - 1, dp, vis);
  dp[x][y] = min(d1, min(d2, min(d3, d4)));
  return dp[x][y];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> h >> w;
  vector<vector<char>> v(30, vector<char>(30));
  for (long long int i = 0; i < h; i++) {
    for (long long int j = 0; j < w; j++) {
      cin >> v[i][j];
    }
  }
  long long int ans = 0;
  for (long long int i = 0; i < h; i++) {
    for (long long int j = 0; j < w; j++) {
      for (long long int k = 0; k < h; k++)
        for (long long int z = 0; z < w; z++) {
          if (v[i][j] == '.' && v[k][z] == '.') {
            flag = false;
            vector<vector<int>> dp(30, vector<int>(30, -1));
            vector<vector<bool>> vis(30, vector<bool>(30, false));
            long long int tempans = solve(v, i, j, k, z, i, j, dp, vis);
            if (flag) ans = max(tempans, ans);
          }
        }
    }
  }
  cout << ans << '\n';
  return 0;
}
