#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for(int i = 0;i < (int)(n);i++)
int main() {
  const int dx[4]  = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}, inf = 10e9;
  int H, W, nh, nw, m = 0;cin >> H >> W;
  P p;
  vector<string> v(H);
  vector<vector<int>> d(H, vector<int>(W));
  queue<P> q;
  rep(i, H) cin >> v[i];
  rep(i, H) rep(j, W) if(v[i][j] == '.') {
    rep(k, H) rep(l, W) d[k][l] = inf;
    q.push(P(i, j));
    d[i][j] = 0;
    while(q.size() != 0) {
      p = q.front();
      q.pop();
      rep(k, 4) {
        nh = p.first + dx[k], nw = p.second + dy[k];
        if(0 <= nh && nh < H && 0 <= nw && nw < W && v[nh][nw] == '.' 
           && d[nh][nw] == inf) {
          q.push(P(nh, nw));
          d[nh][nw] = d[p.first][p.second] + 1;
          if(m < d[nh][nw]) m = d[nh][nw];
        }
      }
    }
  }
  cout << m << endl;
}