#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
vector<pair<long long, long long>> dirs = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long h, w;
  cin >> h >> w;
  long long matrix[h][w];
  long long node[h][w];
  long long adj[h * w][h * w];
  memset(adj, 0, sizeof(adj));
  long long cnt = 0;
  memset(matrix, 0, sizeof(matrix));
  for (long long i = 0; i < h; ++i) {
    for (long long j = 0; j < w; ++j) {
      char ch;
      cin >> ch;
      node[i][j] = cnt++;
      if (ch == '.')
        matrix[i][j] = 1;
      else
        adj[node[i][j]][node[i][j]] = INF;
    }
  }
  for (long long i = 0; i < h * w; ++i) {
    for (long long j = 0; j < h * w; ++j) {
      if (adj[i][j] == INF) continue;
      adj[i][j] = (i == j ? 0 : INF);
    }
  }
  for (long long i = 0; i < h; ++i) {
    for (long long j = 0; j < w; ++j) {
      for (auto& x : dirs) {
        if (i + x.first >= 0 && i + x.first < h && j + x.second >= 0 &&
            j + x.second < w && matrix[i + x.first][j + x.second]) {
          adj[node[i][j]][node[i + x.first][j + x.second]] = 1;
        }
      }
    }
  }
  for (long long k = 0; k < h * w; ++k) {
    for (long long i = 0; i < h * w; ++i) {
      for (long long j = 0; j < h * w; ++j) {
        adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
      }
    }
  }
  long long ans = 0;
  for (long long i = 0; i < h * w; ++i) {
    for (long long j = 0; j < h * w; ++j) {
      if (adj[i][j] >= INF) continue;
      ans = max(ans, adj[i][j]);
    }
  }
  cout << ans;
}
