#include<bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
#define int long long

int H, W;
char S[22][22];
bool s[22][22] = {false};
int ans = 0;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int bfs(int i,int j){
  vector<vector<int>> dist(H,vector<int>(W,-1));
  queue<pair<int,int>> que;

  int res = 0;
  que.push({i,j});
  dist[i][j] = 0;
  while(!que.empty()){
    i = que.front().first, j = que.front().second;
    res = max(res,dist[i][j]);
    que.pop();
    for(int dir = 0;dir < 4;dir++){
      int nx = i+dx[dir],ny = j+dy[dir];
      if(nx < 0 || nx >= H || ny < 0 || ny >= W || S[nx][ny] == '#') continue;
      if(dist[nx][ny] == -1){
        dist[nx][ny] = dist[i][j] + 1;
        que.push({nx, ny});
      }
    }
  }
  return res;
}

signed main(){
  cin >> H >> W;
  rep(i,H)rep(j,W)cin >> S[i][j];
  rep(i,H)rep(j,W){
    if(S[i][j] == '.')ans = max(ans,bfs(i,j));
  }
  cout << ans;
}
