#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
  int dx[4] = {-1, 0, 1, 0}; 
  int dy[4] = {0, -1, 0, 1};
  int h, w;
  cin >> h >> w;
  vector<string> S(h);
  rep(i,h) cin >> S[i];

  int ans = 0;
  rep(i,h) rep(j,w) {
    if (S[i][j] == '#') continue;
    queue<P> que;
    que.push(P(i,j));
    vector< vector<int> > dist(h, vector<int>(w, -1));
    dist[i][j] = 0;
    P cur;
    while(!que.empty()) {
      cur = que.front(); que.pop();
      rep(i,4) {
        int y = cur.first + dy[i];
        int x = cur.second + dx[i];
        if (x >= w || y >= h || x < 0 || y < 0) continue;
        if (dist[y][x] != -1) continue;
        if (S[y][x] == '.') {
          que.push(P(y,x));
          dist[y][x] = dist[cur.first][cur.second] + 1;
          ans = max(ans, dist[y][x]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}