#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
#define vcin(a)                          \
    for (int i = 0; i < (a).size(); i++) \
        cin >> (a)[i];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int H, W;

int bfs(int H,int W,vector<vchar> S,int x,int y)
{
    vvint distance(W, vint(H));
    if (S[x][y] == '#')
    {
        return 0;
    }
    pair<int, int> start = {x, y};
    vector<vector<bool>> arrived(W + 1, vector<bool>(H + 1));
    rep(Y, H)
    {
        rep(X, W)
        {
            distance[X][Y] = -1;
        }
    }
    distance[x][y] = 0;
    queue<pair<int, int>> q;
    q.push(start);
    while (!q.empty())
    {
        pair<int, int> now = q.front();
        int nowx = now.first;
        int nowy = now.second;
        int dis = distance[nowx][nowy];
        arrived[nowx][nowy] = true;
        q.pop();
        rep(k, 4)
        {
            if ((nowx + dx[k] < W and nowx + dx[k] >= 0 and nowy + dy[k] < H and nowy + dy[k] >= 0 and S[nowx + dx[k]][nowy + dy[k]] == '.') and arrived[nowx + dx[k]][nowy + dy[k]] == 0)
            {
                q.push({nowx + dx[k], nowy + dy[k]});
                distance[nowx + dx[k]][nowy + dy[k]] = dis + 1;
            }
        }
    } //この時点で最短経路は出てる
    rep(s, W)
    {
        rep(t, H)
        {
            ans = max(distance[s][t], ans);
        }
    }
    return ans;
}

int main()
{
    
    cin >> H >> W;
    vector<vector<char>> S(W, vchar(H));
    int Answer = 0;

    rep(y, H)
    {
        rep(x, W)
        {
            cin >> S[x][y];
        }
    }
    rep(y, H)
    {
        rep(x, W)
        {
            Answer = max(Answer, bfs(H, W, S, x, y));
        }
    }
    cout << Answer;
    return 0;
}
