#include <iostream>
#include <vector>
#include <queue>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const int MOD = 1000000007;
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

int H, W;

int bfs(vector<vector<char> > &S, int i, int j) {
    VVI dist(H,VI(W,-1));
    dist[i][j] = 0;
    queue<PII> q;
    q.push({i,j});
    while(!q.empty()) {
        i = q.front().first;
        j = q.front().second;
        q.pop();
        if (0 < i && dist[i-1][j] == -1 && S[i-1][j] == '.') {
            q.push({i-1,j});
            dist[i-1][j] = dist[i][j] + 1;
        }
        if (i < H-1 && dist[i+1][j] == -1 && S[i+1][j] == '.') {
            q.push({i+1,j});
            dist[i+1][j] = dist[i][j] + 1;
        }
        if (0 < j && dist[i][j-1] == -1 && S[i][j-1] == '.') {
            q.push({i,j-1});
            dist[i][j-1] = dist[i][j] + 1;
        }
        if (j < W-1 && dist[i][j+1] == -1 && S[i][j+1] == '.') {
            q.push({i,j+1});
            dist[i][j+1] = dist[i][j] + 1;
        }
    }
    int res = 0;
    REP(i,H) {
        REP(j,W) {
            res = max(res, dist[i][j]);
        }
    }
    return res;
}


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int ans = 0;
    
    
    cin >> H >> W;
    vector<vector<char> > S(H,vector<char>(W));
    VVI G(H,VI(W));
    REP(i,H) REP(j,W) {
        cin >> S[i][j];
    }
    
    REP(i,H) REP(j,W) {
        if (S[i][j] == '.') ans = max(ans, bfs(S, i, j));
    }

    cout << ans << endl;

    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc176/abc176_e && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc176/abc176_e && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc176/abc176_e && sh shellscripts/submit_cpp.sh
*/


Measured memory_bytes: 3200