#include <bits/stdc++.h>
using namespace std;
int fl[30][30][30][30], maze[30][30];
string s[50];
int main() {
  int n, m, x, y;
  cin >> n >> m;
  memset(maze, -1, sizeof maze);
  ;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '.') {
        maze[i + 1][j + 1] = 0;
        x = i + 1;
        y = j + 1;
      }
    }
  }
  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= m + 1; j++) {
      for (int k = 0; k <= n + 1; k++) {
        for (int l = 0; l <= m + 1; l++) {
          fl[i][j][k][l] = 100005;
        }
      }
    }
    fl[i][i][i][i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (!maze[i][j] && !maze[i + 1][j]) {
        fl[i][j][i + 1][j] = 1;
        fl[i + 1][j][i][j] = 1;
      }
      if (!maze[i][j] && !maze[i - 1][j]) {
        fl[i][j][i - 1][j] = 1;
        fl[i - 1][j][i][j] = 1;
      }
      if (!maze[i][j] && !maze[i][j + 1]) {
        fl[i][j][i][j + 1] = 1;
        fl[i][j + 1][i][j] = 1;
      }
      if (!maze[i][j] && !maze[i][j - 1]) {
        fl[i][j][i][j - 1] = 1;
        fl[i][j - 1][i][j] = 1;
      }
    }
  }
  for (int kx = 0; kx <= n; kx++) {
    for (int ky = 0; ky <= m; ky++) {
      for (int ix = 0; ix <= n; ix++) {
        for (int iy = 0; iy <= m; iy++) {
          for (int jx = 0; jx <= n; jx++) {
            for (int jy = 0; jy <= m; jy++) {
              fl[ix][iy][jx][jy] = min(fl[ix][iy][jx][jy],
                                       fl[ix][iy][kx][ky] + fl[kx][ky][jx][jy]);
            }
          }
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= m + 1; j++) {
      for (int k = 0; k <= n + 1; k++) {
        for (int l = 0; l <= m + 1; l++) {
          if (fl[i][j][k][l] < 100005) {
            ans = max(ans, fl[i][j][k][l]);
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
