#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }

int R, C;
char c[21][21];
int ans[21][21];

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

int main(){
	cin >> R >> C;
	for(int i = 0; i < R; ++i){
		for(int j = 0; j < C; ++j){
			cin >> c[i][j];
		}
	}
  int tmp=-1;
	rep(sx,C){
    int ans[21][21];
    queue< pair<int, int> > q;
    memset(ans,0,sizeof(ans));
    rep(sy,R){
      rep(gx,C){
        rep(gy,R){
          q.push(make_pair(sy, sx));
        	ans[sy][sx] = 0;
        	while(!q.empty()){
        		pair<int, int> pos = q.front();
        		q.pop();
        		for(int i = 0; i < 4; ++i){
        			int nowy = pos.first + dy[i], nowx = pos.second + dx[i];
        			if(ans[nowy][nowx] != 0) continue;
        			if(0 <= nowx && nowx < C && 0 <= nowy && nowy < R){
        				if(c[nowy][nowx] == '.'){
        					ans[nowy][nowx] = ans[pos.first][pos.second] + 1;
        					q.push(make_pair(nowy, nowx));
        				}
        			}
        		}
        	}
        	
        }
        chmax(tmp,ans[gy][gx]);
      }
    }
  }
  cout << tmp << endl;
}
