#include <bits/stdc++.h>
using namespace std;
using LL = long long;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1e9;
const LL LLINF = 1e16;
int W, H;
int cost[101][101];
int bfs(vector<string>& s, int ii, int jj) {
  int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
  queue<pair<int, int>> que;
  que.push(make_pair(ii, jj));
  cost[ii][jj] = 0;
  int ret = 0;
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int ny = p.first + dy[i], nx = p.second + dx[i];
      if (nx < 0 || ny < 0 || nx >= W || ny >= H) continue;
      if (s[ny][nx] == '#') continue;
      if (cost[ny][nx] != -1) continue;
      cost[ny][nx] = cost[p.first][p.second] + 1;
      chmax(ret, cost[ny][nx]);
      que.push(make_pair(ny, nx));
    }
  }
  return ret;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> H >> W;
  vector<string> s(H);
  for (int i = (0); i < (H); i++) cin >> s[i];
  int ans = 0;
  for (int i = (0); i < (H); i++)
    for (int j = (0); j < (W); j++) {
      memset(cost, -1, sizeof(cost));
      chmax(ans, bfs(s, i, j));
    }
  cout << ans << endl;
}
