#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  char s[25][25];
  for (int i = 0; i < (h); i++)
    for (int j = 0; j < (w); j++) cin >> s[i][j];
  int dx[4] = {1, 0, -1, 0};
  int dy[4] = {0, 1, 0, -1};
  int ans = 0;
  for (int si = 0; si < (h); si++)
    for (int sj = 0; sj < (w); sj++) {
      for (int gi = 0; gi < (h); gi++)
        for (int gj = 0; gj < (w); gj++) {
          int d[25][25];
          for (int i = 0; i < (h); i++)
            for (int j = 0; j < (w); j++) d[i][j] = -1;
          d[si][sj] = 0;
          queue<pair<int, int> > q;
          q.push({si, sj});
          while (q.size()) {
            int x, y;
            tie(x, y) = q.front();
            q.pop();
            for (int i = 0; i < (4); i++) {
              int nx = x + dx[i], ny = y + dy[i];
              if (nx >= h || ny >= w) continue;
              if (s[nx][ny] == '.' && d[nx][ny] == -1) {
                d[nx][ny] = d[x][y] + 1;
                q.push({nx, ny});
              }
            }
          }
          ans = max(d[gi][gj], ans);
        }
    }
  cout << ans << endl;
  return 0;
}
