#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48), ch = getchar();
  x *= f;
  return;
}
template <typename T>
void write(T x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
  return;
}
int n, m;
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int mp[25][25];
bool book[25][25];
int sx, sy, tx, ty;
int ans = 0;
int dis;
void dfs(int step, int x, int y) {
  if (x == tx && y == ty) dis = min(dis, step);
  if (dis <= step) return;
  if (x < 0 || x > n || y < 0 || y > m) return;
  if (book[x][y]) return;
  if (!mp[x][y]) return;
  book[x][y] = 1;
  for (int i = 0; i < 4; i++) dfs(step + 1, x + dx[i], y + dy[i]);
  book[x][y] = 0;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      char ch;
      cin >> ch;
      if (ch == '.')
        mp[i][j] = 1;
      else
        mp[i][j] = 0;
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      for (int k = 1; k <= n; k++)
        for (int l = 1; l <= m; l++) {
          sx = i, sy = j, tx = k, ty = l;
          if (!mp[sx][sy] || !mp[tx][ty]) continue;
          memset(book, 0, sizeof(book));
          dis = 999999999;
          dfs(0, sx, sy);
          ans = max(ans, dis);
        }
  cout << ans << endl;
  return 0;
}
