//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  int dx[] = {1,0,-1,0};
  int dy[] = {0,1,0,-1};
  int h,w;
  cin >> h >> w;
  string s[h];
  rep(i,h) cin >> s[i];
  int dp[w][h] = {0};
  int sx,sy;
  int ans = 0;
  queue<int> px;
  queue<int> py;
  rep(i,h){
    rep(j,w){
      if(s[i].substr(j,1) == "#") continue;
      px.push(j);
      py.push(i);
      // printf("\n%d %d\n\n", j,i);
      while(!px.empty()){
        sx = px.front(); px.pop();
        sy = py.front(); py.pop();
        // printf("%d %d\n", sx, sy);
        rep(l,4){
          if(0 <= sx+dx[l] && sx+dx[l] <= w-1){
            if(0 <= sy+dy[l] && sy+dy[l] <= h-1){
              if(s[sy+dy[l]].substr(sx+dx[l],1) != "#"){
                if(dp[sx+dx[l]][sy+dy[l]] == 0){
                  dp[sx+dx[l]][sy+dy[l]] = dp[sx][sy] + 1;
                  px.push(sx+dx[l]);
                  py.push(sy+dy[l]);
                }else if(dp[sx+dx[l]][sy+dy[l]] > dp[sx][sy] + 1){
                  dp[sx+dx[l]][sy+dy[l]] = dp[sx][sy] + 1;
                  px.push(sx+dx[l]);
                  py.push(sy+dy[l]);
                }
              }
            }
          }
        }
      }
    }
    rep(k,h){
      rep(l,w){
        ans = max(ans,dp[l][k]);
        dp[l][k] = 0;
      }
    }
  }
  printf("%d", ans);

  return 0;
}
