#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};

int main(){
  int H, W;
  cin >> H >> W;
  char S[H][W];
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++) cin >> S[i][j];
  }
  
  int ans=0;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(S[i][j]=='#') continue;
      queue<pair<int, int>> que;
      vector<vector<int>> dist(H, vector<int>(W, -1));
      que.push({i, j});
      dist[i][j]=0;
      while(!que.empty()){
        int x, y;
        tie(y, x) = que.front();
        que.pop();
        for(int k=0; k<4; k++){
          int nx = x + dx[k], ny = y+dy[k];
          if(nx < 0 || W <= nx || ny < 0 || H <= ny || S[ny][nx] == '#'|| dist[ny][nx] != -1) continue;
          dist[ny][nx] = dist[y][x] + 1;
          que.push({ny, nx});
        }
      }
      int diss=0;
      for(int k=0; k<H; k++){
        for(int l=0; l<W; l++) diss=max(diss, dist[k][l]);
      }
      ans=max(ans, diss);
    }
  }
  cout << ans << endl;
}