#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef pair<int, int> P;
const int INF = 1000000000;

char maze[100][101];
int N, M; 
int sx, sy;
int d[100][101];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int bfs(){
    queue<P> que;
    rep(i, N) rep(j, M) d[i][j] = INF; 
    que.push(P(sx, sy)); 
    d[sx][sy] = 0;
    while(que.size()){
        P p = que.front(); que.pop();
        rep(i, 4){
            int nx = p.first + dx[i], ny = p.second + dy[i];
            if (0 <= nx && nx < N && 0 <= ny && ny < M && maze[nx][ny] != '#' && d[nx][ny] == INF){
                que.push(P(nx, ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
  int maxa =0;
  rep(i,N) rep(j,M) if(d[i][j]!=INF) maxa=max(maxa,d[i][j]);
  return maxa;
}

int main() {
  cin>>N>>M;
  rep(i,N) rep(j,M) cin>>maze[i][j];
  int res=0;
  rep(i,N) rep(j,M) if(maze[i][j]!='#'){
    sx = i, sy = j;
    res = max(bfs(),res);
   }
    printf("%d\n", res);

}