#include <bits/stdc++.h>
using namespace std;
const long long INF = 100000000;
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;
}
int main() {
  long long h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (long long i = 0; i < (h); i++) cin >> s[i];
  queue<pair<long long, long long> > que;
  vector<pair<long long, long long> > G;
  G.push_back(make_pair(1, 0));
  G.push_back(make_pair(-1, 0));
  G.push_back(make_pair(0, 1));
  G.push_back(make_pair(0, -1));
  long long ans = 0;
  for (long long i = 0; i < (h); i++)
    for (long long j = 0; j < (w); j++) {
      vector<vector<long long> > dist(h, vector<long long>(w, -1));
      dist[i][j] = 0;
      que.push(make_pair(i, j));
      while (!que.empty()) {
        pair<long long, long long> v = que.front();
        que.pop();
        ans = max(ans, dist[v.first][v.second]);
        for (auto nv : G) {
          long long x = v.first + nv.first, y = v.second + nv.second;
          if (x >= 0 && x < h && y >= 0 && y < w && s[x][y] == '.' &&
              dist[x][y] == -1) {
            dist[x][y] = dist[v.first][v.second] + 1;
            que.push(make_pair(x, y));
          }
        }
      }
    }
  cout << ans << endl;
}
