#include <bits/stdc++.h>
using namespace std;

#define For(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e18
#define INT_INF 1e9

typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;

vector<char> boin = {'a','i','u','e','o'};
vector<char> alphabet = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main(){
    int H,W;
    cin >> H >> W;
    char maze[H][W];
    Rep(i,H){
        Rep(j,W){
            cin >> maze[i][j];
        }
    }
    int dis[H][W][H][W] = {};
    queue<pair<int,int>> que; 
    Rep(i,H){
        Rep(j,W){
            Rep(k,H){
                Rep(l,W){
                    if(i == k && j == l)dis[i][j][k][l] = 0;
                    else dis[i][j][k][l] = -1;
                }
            }
        }
    }
    Rep(i,H){
        Rep(j,W){
            que.emplace(i,j);
            while(!que.empty()){
                int x = que.front().first;
                int y = que.front().second;
                que.pop();
                Rep(d,4){
                    if(x + dx[d] < 0 || x + dx[d] >= H || y + dy[d] < 0 || y + dy[d] >= W)continue;
                    if(maze[x + dx[d]][y + dy[d]] != '#' && dis[i][j][x+dx[d]][y+dy[d]] == -1){
                        que.emplace(x + dx[d],y + dy[d]);
                        dis[i][j][x + dx[d]][y + dy[d]] = dis[i][j][x][y] + 1;
                    }
                }
            }
        }
    }
    int ans = 0;
    Rep(i,H){
        Rep(j,W){
            Rep(k,H){
                Rep(l,W)ans = max(ans,dis[i][j][k][l]);
            }
        }
    }
    cout << ans << endl;
    //cin >> H;
}