/*
lakshaygpt28
Lakshay Gupta
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
using vll = vector < ll >;

template < typename T > using OrderedMultiSet = tree < T, null_type, less_equal < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;


#ifndef ONLINE_JUDGE
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define debug(...)
#endif

#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define eb emplace_back
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 22;

char s[N][N];
ll dp[N][N];
bool vis[N][N];
int h, w;
void dfs(int i, int j);

int main() {
    fast_io();
    cin >> h >> w;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            s[i][j] = '#';
            cin >> s[i][j];
        }
    }
    ll rst = 0;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (s[i][j] == '.') {
                for (int i = 0; i < N; i++) {
                    for (int j = 0; j < N; j++) {
                        dp[i][j] = INT_MAX;
                        vis[i][j] = 0;
                    }
                }
                dp[i][j] = 0;
                dfs(i, j);
                for (int i2 = 1; i2 <= h; i2++) {
                    for (int j2 = 1; j2 <= w; j2++) {
                        if (s[i2][j2] == '.') {
                            ll cur = dp[i2][j2];
                            rst = max(rst, cur);
                        }
                    }
                }
            }
        }
    }
    cout << rst << "\n";
    return 0;
}

void dfs(int i, int j) {
    // debug(i, j, x, y);
    if (i < 1 or j < 1 or i > h or j > w or s[i][j] == '#' or vis[i][j]) {
        return;
    }
    if (s[i + 1][j] == '.') {
        dp[i + 1][j] = min(dp[i + 1][j], 1 + dp[i][j]);
    }
    if (s[i - 1][j] == '.') {
        dp[i - 1][j] = min(dp[i - 1][j], 1 + dp[i][j]);
    }
    if (s[i][j + 1] == '.') {
        dp[i][j + 1] = min(dp[i][j + 1], 1 + dp[i][j]);
    }
    if (s[i][j - 1] == '.') {
        dp[i][j - 1] = min(dp[i][j - 1], 1 + dp[i][j]);
    }
    vis[i][j] = 1;
    dfs(i + 1, j);
    dfs(i - 1, j);
    dfs(i, j + 1);
    dfs(i, j - 1);
}
