#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int (i)=0; i<(int)(n); i++)

const int inf = (int)1e9 + 7;
char s[25][25];
vector <vector <int> > d;
const int dx[] = {0,0,1,-1};
const int dy[] = {1,-1,0,0};
int main(void){
  	int N, M;
  	cin >> N >> M;
  	REP(i,N) cin >> s[i];
  	
  	int ans = 0;
  	REP(i,N) REP(j,M) if (s[i][j] != '#'){
				d.clear();
				d.resize(N, vector<int> (M, inf));
				queue < pair <int, int> > q;
				q.push({i, j});
				d[i][j] = 0;
				while (!q.empty()){
		  		pair<int, int> p = q.front();
		  		q.pop();
		  		REP(D,4){
				  	int nx = p.first + dx[D];
				  	int ny = p.second + dy[D];
				  	if (nx >= 0 && nx < N && ny >= 0 && ny < M && s[nx][ny] != '#' && d[nx][ny] > d[p.first][p.second] + 1) {
						d[nx][ny] = d[p.first][p.second] + 1;
						ans = max(ans, d[nx][ny]);
						q.push({nx, ny});
				  	}
		  		}
			}
	}
  	cout << ans << endl;
  	return 0;
}