#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
//左　上　右　下

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];

    int max = 0;

    rep(si, h)rep(sj, w){
        if(s[si][sj]=='#') continue;
        vvi dist(h, vi(w, INF));
        queue<P> q;
        auto update = [&](int i, int j, int x){
            if(dist[i][j] != INF) return;
            dist[i][j] = x;
            q.push(P(i, j));    
        };
        update(si, sj, 0);
        while(!q.empty()){
            int i = q.front.fi;
            int j = q.front.se; q.pop();
            rep(dir, 4){
                int ni = i+di[dir];
                int nj = j+dj[dir];
                if(ni<0||ni>=h||nj<0||nj>=w) continue;
                if(s[ni][nj]=='#') continue;
                update(ni, nj, dist[i][j]+1);
            }
        }
        rep(i, h)rep(j, w){
            if(dist[i][j] == INF) continue;
            if(max < dist[i][j]) max = dist[i][j];
        }
    }
    cout << max << endl;
    return 0;
}