#include <bits/stdc++.h>
using namespace std;
signed main() {
  int h, w;
  scanf("%d %d", &h, &w);
  char s[30][30];
  scanf("%c", &s[0][0]);
  for (int i{0}; i < (int)h; ++i) {
    for (int j{0}; j < (int)w; ++j) {
      scanf("%c", &s[i][j]);
    }
    scanf("%c", &s[25][25]);
  }
  int ans = 0;
  for (int i{0}; i < (int)h; ++i)
    for (int j{0}; j < (int)w; ++j) {
      queue<tuple<int, int, int>> que;
      que.emplace(i, j, 0);
      int dist[30][30];
      constexpr int inf = 1 << 28;
      for (int k{0}; k < (int)h; ++k)
        for (int l{0}; l < (int)w; ++l) dist[k][l] = inf;
      while (!que.empty()) {
        int y, x, c;
        tie(y, x, c) = que.front();
        que.pop();
        if (dist[y][x] > c) {
          if (c > ans) ans = c;
          dist[y][x] = c;
          int ny{y}, nx{x};
          ny--;
          if (ny != -1 && s[ny][nx] != '#') que.emplace(ny, nx, c + 1);
          ny += 2;
          if (ny != h && s[ny][nx] != '#') que.emplace(ny, nx, c + 1);
          ny--;
          nx--;
          if (nx != -1 && s[ny][nx] != '#') que.emplace(ny, nx, c + 1);
          nx += 2;
          if (nx != w && s[ny][nx] != '#') que.emplace(ny, nx, c + 1);
        }
      }
    }
  printf("%d", ans);
}
