#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
//onst int INF = 2e9+100;
const int INF = 1e9+7;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

LL modinv(LL a) {
    LL b = MOD, u = 1, v = 0;
    while (b) {
        LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}

VVI m;

void warshall_floyd(int n) { // nは頂点数
  for (int i = 0; i < n; i++)      // 経由する頂点
    for (int j = 0; j < n; j++)    // 開始頂点
      for (int k = 0; k < n; k++)  // 終端
        m[j][k] = min(m[j][k], m[j][i] + m[i][k]);
}

void Main()
{
    int h,w; cin >> h >> w;

    vector<vector<char>> s(h);
    REP(i,h){
        s[i].resize(w);
        REP(j,w){
            cin >> s[i][j];
        }
    }

    m.resize(h*w);
    REP(i,h*w){
        m[i].resize(h*w,INF);
        m[i][i] = 0;
    }

    REP(i,h){
        REP(j,w){
            //if(i==j){
            //    m[i][j] = 0;
            //}
            if(s[i][j] == '#'){
                continue;
            }
            if(i!=0 && s[i-1][j] == '.'){
                m[i*w + j][(i-1)*w + j] = 1;
                m[(i-1)*w + j][i*w + j] = 1;
            }
            if(i!=h-1 && s[i+1][j] == '.'){
                m[i*w + j][(i+1)*w + j] = 1;
                m[(i+1)*w + j][i*w + j] = 1;
            }
            if(j!=0 && s[i][j-1] == '.'){
                m[i*w + j][i*w + j-1] = 1;
                m[i*w + j-1][i*w + j] = 1;
            }
            if(i!=w-1 && s[i][j+1] == '.'){
                m[i*w + j][i*w + j+1] = 1;
                m[i*w + j+1][i*w + j] = 1;
            }
        }
    }

    warshall_floyd(h*w);

    int result = 0;

    REP(i,h*w){
        REP(j,h*w){
            if(m[i][j] != INF){
                result = max(result,m[i][j]);
            }
        }
    }

    cout << result << endl;   

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 896