#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>

const ll INF = pow(10, 9) + 7;


int main() {
  int H,W;
  cin >> H >> W;
  vector<vector<char>> map(H,vector<char>(W));
  rep(i,H)rep(j,W) cin >> map[i][j];
  
  int ans = 0;
  rep(si,H)rep(sj,W){
    if(map[si][sj] == '#') continue;
    vector<vector<int>> a(H,vector<int>(W,-1));
    queue<P> q;
    
    auto update = [&](int i,int j,int x){
      if(i<0 || i>=H || j<0 || j>=W) return;
      if(map[i][j] == '#' || a[i][j] != -1) return;
      q.push(P(i,j));
      a[i][j] = x;
      return;
    };
    
    update(si,sj,0);
    
    while(!q.empty()){
      P pp = q.front();q.pop();
      int i = pp.first,j=pp.second;
      update(i+1,j,a[i][j]+1);
      update(i-1,j,a[i][j]+1);
      update(i,j+1,a[i][j]+1);
      update(i,j-1,a[i][j]+1);
      if(q.empty()) ans = max(ans,a[i][j]);
    }
  }
  
  cout << ans << endl;
}