#include <bits/stdc++.h>
using namespace std;
int h, w;
bool a[50][50];
bool ok(int x, int y){
  return 0<=x and x < h and 0<= y and y < w and a[x][y];
}
int dx[] = {-1,0,0,1};
int dy[] = {0,-1,1,0};
int main(){
  cin >> h >> w;
  for(int i = 0; i < h; i++){
    string s;
    cin >> s;
    for(int j = 0; j < w; j++){
      a[x][y] = (s[j] == '.');
    }
  }
  int ans = 0;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(!ok(i,j))continue;
      queue<pair<int,int>> q;
      q.emplace(i, j);
      int dist[50][50] = {};
      memset(dist, -1, sizeof(dist));
      int ma = -1;
      dist[i][j] = 0;
      while(!q.empty()){
        auto p = q.front();q.pop();
        ma = max(ma, dist[p.first][p.second]);
        for(int k = 0; k < 4; k++){
          int x = p.first + dx[k];
          int y = p.second + dy[k];
          if(!ok(x,y))continue;
          if(dist[x][y]==-1){
            dist[x][y] = dist[p.first][p.second] + 1;
            q.emplace(x, y);
          }
        }
      }
      ans = max(ma, ans);
    }
  }
  cout << ans << endl;
}