#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int h,w;
    cin >> h >> w;
    VS s(h);
    REP(i,0,h) cin >> s[i];
    VVI d(h,VI(w));
    vector<vector<bool>> v(h, vector<bool>(w));
    REP(i,0,h) {
        bool b = false;
        REP(j,0,w) {
            dump(i);
            dump(j);
            if (s[i][j] !='.') continue;
            deque<int> q;
            q.push_back(i*w+j);
            v[i][j] = true;
            while (!q.empty()) {
                dump("mid1");
                int p = q.front();
                q.pop_front();
                int x = p / w, y = p % w;
                //cerr << x << ", " << y << endl;
                dump("mid0");
                if (x - 1 >= 0 && s[x-1][y] == '.' && v[x-1][y] == false) {
                    q.push_back((x-1)*w+y);
                    v[x-1][y] = true;
                    d[x-1][y] = d[x][y] + 1;
                }
                dump("mid0");
                if (x + 1 < h && s[x+1][y] == '.' && v[x+1][y] == false) {
                    q.push_back((x+1)*w+y);
                    v[x+1][y] = true;
                    d[x+1][y] = d[x][y] + 1;
                }
                dump("mid0");
                if (y - 1 >= 0 && s[x][y-1] == '.' && v[x][y-1] == false) {
                    q.push_back(x*w+y-1);
                    v[x][y-1] = true;
                    d[x][y-1] = d[x][y] + 1;
                }
                dump("mid0");
                if (y + 1 < w && s[x][y+1] == '.' && v[x][y+1] == false) {
                    q.push_back(x*w+y+1);
                    v[x][y+1] = true;
                    d[x][y+1] = d[x][y] + 1;
                }
            }
            dump("mid");
            b = true;
            break;
        }
        if (b) break;
    }
    dump("mid0");

    int maxx = 0, maxy = 0;
    REP(i,0,h) REP(j,0,w) if (d[i][j] > d[maxx][maxy]) {
        maxx = i;
        maxy = j;
    }
    REP(i,0,h) REP(j,0,w) {
        v[i][j] = false;
    }
    d[maxx][maxy] = 0;
    v[maxx][maxy] = true;

    dump("mid");
    deque<int> q;
    q.push_back(maxx*w+maxy);
    while (!q.empty()) {
        int p = q.front();
        q.pop_front();
        int x = p / w, y = p % w;
        if (x - 1 >= 0 && s[x-1][y] == '.' && v[x-1][y] == false) {
            q.push_back((x-1)*w+y);
            v[x-1][y] = true;
            d[x-1][y] = d[x][y] + 1;
        }
        if (x + 1 < h && s[x+1][y] == '.' && v[x+1][y] == false) {
            q.push_back((x+1)*w+y);
            v[x+1][y] = true;
            d[x+1][y] = d[x][y] + 1;
        }
        if (y - 1 >= 0 && s[x][y-1] == '.' && v[x][y-1] == false) {
            q.push_back(x*w+y-1);
            v[x][y-1] = true;
            d[x][y-1] = d[x][y] + 1;
        }
        if (y + 1 < w && s[x][y+1] == '.' && v[x][y+1] == false) {
            q.push_back(x*w+y+1);
            v[x][y+1] = true;
            d[x][y+1] = d[x][y] + 1;
        }
    }
    int ans = 0;
    REP(i,0,h) REP(j,0,w) ans = max(ans, d[i][j]);
    cout << ans << endl;
}

signed main() {
    solve();
    
    return 0;
}