#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  char a[n + 5][m + 5];
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    for (int j = 1; j <= m; j++) {
      a[i][j] = s[j - 1];
    }
  }
  int dx[] = {0, -1, 0, 1};
  int dy[] = {1, 0, -1, 0};
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      pair<int, int> start = make_pair(i, j);
      int vis[n + 5][m + 5];
      memset(vis, 0, sizeof(vis));
      queue<pair<int, int> > q;
      q.push(start);
      vis[i][j] = 1;
      while (!q.empty()) {
        pair<int, int> cur = q.front();
        q.pop();
        for (int k = 0; k < 4; k++) {
          pair<int, int> next =
              make_pair(cur.first + dx[k], cur.second + dy[k]);
          if (vis[next.first][next.second] == 0 &&
              a[next.first][next.second] == '.' && next.first >= 1 &&
              next.first <= n && next.second >= 1 && next.second <= m) {
            vis[next.first][next.second] = vis[cur.first][cur.second] + 1;
            q.push(next);
          }
        }
      }
      int p = 0;
      for (int k = 1; k <= n; k++) {
        for (int l = 1; l <= m; l++) {
          p = max(p, vis[k][l]);
        }
      }
      ans = max(ans, p);
    }
  }
  cout << ans - 1 << endl;
  return 0;
}
