#include <bits/stdc++.h>
using namespace std;
const int maxn = 30;
int n, m, a[maxn][maxn], dt[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}, ans,
                         p[maxn][maxn];
bool vis[maxn][maxn];
char s[maxn];
inline void DFS(int x, int y) {
  for (int i = (0), _end_ = (3); i <= _end_; ++i) {
    int u = dt[i][0] + x;
    int v = dt[i][1] + y;
    if (a[u][v] && p[u][v] > p[x][y] + 1 && !vis[u][v]) {
      p[u][v] = p[x][y] + 1;
      vis[u][v] = true;
      DFS(u, v);
      vis[u][v] = false;
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (1), _end_ = (n); i <= _end_; ++i) {
    scanf("%s", s + 1);
    for (int j = (1), _end_ = (m); j <= _end_; ++j)
      if (s[j] == '.') a[i][j] = 1;
  }
  for (int i = (1), _end_ = (n); i <= _end_; ++i)
    for (int j = (1), _end_ = (m); j <= _end_; ++j)
      if (a[i][j]) {
        memset((vis), 0, sizeof(vis));
        memset(p, 0x3f, sizeof(p));
        p[i][j] = 0;
        vis[i][j] = true;
        DFS(i, j);
        for (int k = (1), _end_ = (n); k <= _end_; ++k)
          for (int o = (1), _end_ = (m); o <= _end_; ++o)
            ans = max(ans, p[k][o]);
      }
  printf("%d\n", ans);
  return 0;
}
