#include <bits/stdc++.h>
using namespace std;
int n, m;
int X[4] = {0, 1, 0, -1};
int Y[4] = {1, 0, -1, 0};
int dfs(char **mat, int sx, int sy, int ex, int ey, int moves, bool **vis) {
  if (sx == ex && sy == ey) {
    return 0;
  }
  vis[sx][sy] = true;
  int temp = 1000;
  for (int i = 0; i < 4; i++) {
    int x = sx + X[i];
    int y = sy + Y[i];
    if (x >= 0 && x < n && y >= 0 && y < m && mat[x][y] == '.' && !vis[x][y]) {
      int ans = 1 + dfs(mat, x, y, ex, ey, moves + 1, vis);
      temp = min(ans, temp);
    }
  }
  vis[sx][sy] = false;
  return temp;
}
int main() {
  cin >> n >> m;
  char **mat = new char *[n];
  bool **vis = new bool *[n];
  for (int i = 0; i < n; i++) {
    mat[i] = new char[m];
    vis[i] = new bool[m];
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) cin >> mat[i][j];
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int I = 0; I < n; I++) {
        for (int J = 0; J < m; J++) {
          if (mat[i][j] == '.' && mat[I][J] == '.' && !vis[i][j])
            ans = max(ans, dfs(mat, i, j, I, J, 0, vis));
        }
      }
    }
  }
  std::cout << ans << std::endl;
  return 0;
}
