#include <bits/stdc++.h>
#include "../lib/graph/graph.hpp"



using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int h, w; cin >> h >> w;
  vector<vector<char>> c(h, vector<char>(w));

  for(int i=0;i<h;++i) {
    for(int j=0;j<w;++j) {
      cin >> c[i][j];
    }
  }

  vector<vector<int>> g(h*w, vi(h*w, INF));
  for(int i=0;i<h*w;++i) {
    g[i][i] = 0;
  }
  vi dr = {0, 0, -1, 1};
  vi dc = {-1, 1, 0, 0};
  for(int i=0;i<h;++i) {
    for(int j=0;j<w;++j) {
      if(c[i][j] != '.') continue;
      for(int k=0;k<4;++k) {
        
        int nxti = i + dr[k], nxtj = j + dc[k];
        //cout << i << ":" << j << ":" << nxti << ":" << nxtj << endl;
        if(!(0 <= nxti && nxti < h && 0 <= nxtj && nxtj < w)) continue;
        if(c[nxti][nxtj] != '.') continue;
        g[i*w+j][nxti*w+nxtj] = 1;
      }
    }
  }

  for(int k=0;k<h*w;++k) {
    for(int i=0;i<h*w;++i) {
      for(int j=0;j<h*w;++j) {
        if(g[i][k] != INF && g[k][j] != INF) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }

  int ans = 0;
  for(int i=0;i<h*w;++i) {
    for(int j=i+1;j<h*w;++j) {
      if(g[i][j] != INF) ans = max(ans, g[i][j]);
    }
  }

  cout << ans << endl;


}
