#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pair<int,int>>

int main(){
    ios::sync_with_stdio(0);
    int h, w, ans = 0;
    cin >> h >> w;
    string maze[h];
    for (int i = 0 ; i < h ; ++i)
        cin >> maze[i];
    int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
    for (int si = 0 ; si < h ; ++si){
        for (int sj = 0 ; sj < w ; ++sj){
            if (maze[si][sj] == '#')
                continue;
            queue<pair<pii,int>> Q;
            bool vis[h][w] = {false};
            Q.push({{si,sj},0});
            while(!Q.empty()){
                int x = Q.front().first.first, y = Q.front().first.second, l = Q.front().second;
                vis[x][y] = true;
                ans = max(ans, l);
                Q.pop();
                for (int i = 0 ; i < 4 ; ++i){
                    if (x+dx[i] >= 0 && x+dx[i] < h && y+dy[i] >= 0 && y+dy[i] < w && !vis[x+dx[i]][y+dy[i]] && maze[x+dx[i]][y+dy[i]] == '.')
                        Q.push({{x+dx[i],y+dy[i]},l+1});
                }
            }
        }
    }
    cout << ans;
    return 0;
}
