#include<bits/stdc++.h>
#define rep(i,a) for(int (i)=0; (i)<(a); (i)++)
#define rep2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
#define chmax(a,b) if(b>a) a = b
#define chmin(a,b) if(b<a) a = b
typedef long long ll;

using namespace std;

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

int main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int h,w; cin >> h >> w; int N = h * w;
      

      char s[h][w];
      rep(i,h)rep(j,w) cin >> s[i][j];

      rep(i,500)rep(j,500) d[i][j] = 1000;
      rep(i,500) dp[i][i] = 0;
      rep(i,h)rep(j,w){
            if(s[i][j] == '#') continue;
            int num = i * w + j;
            rep(k,4){
                  int nx = i + dx[k], ny = j + dy[k];
                  if(nx < 0 || ny < 0 || nx >= h || ny >= w || s[nx][ny] == '#') continue;
                  int num2 = nx * w  + ny;
                  d[num][num2] = 1;
                  d[num2][num] = 1;
            }
      }

      
      rep(i,N)rep(j,N)rep(k,N) chmin(d[j][k], d[j][i] + d[i][k]);

      int ans = 0;
      rep(i,N)rep(j,N) if(d[i][j]< 1000) chmax(ans,d[i][j]);

      cout << ans << endl;

      return 0;
}