#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }
 
int mat[20][20];
 
bool isValid(int x,int y,int n,int m){
  if(x>=0&&x<=n-1&&y>=0&&y<=m-1&&mat[x][y]==1) return true;
  else return false;
}
 
int bfs(pair<int,int> src,int n,int m){
 
  queue<pair<int,int>> qu;
  qu.push(src);
  int cost[n][m];
  bool vis[n][m];
 
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      vis[i][j] = false;
      cost[i][j] = 0;
    }
  }
  
  int maxx = 0;
 	vis[src.first][src.second] = 1;
  while(!qu.empty()){ 
    
    pair<int,int> p = qu.front();
    int x = p.first , y = p.second;
    qu.pop();
    maxx = max(maxx,cost[x][y]);
    
    if(isValid(x,y-1,n,m)&&!vis[x][y-1]){
      qu.push({x,y-1});
      cost[x][y-1] = cost[x][y] + 1;
      vis[x][y-1] = 1;
    }
    
    if(isValid(x,y+1,n,m)&&!vis[x][y+1]){
      qu.push({x,y+1});
      cost[x][y+1] = cost[x][y] + 1;
      vis[x][y+1] = 1;
    }
    
    if(isValid(x-1,y,n,m)&&!vis[x-1][y]){
      qu.push({x-1,y});
      cost[x-1][y] = cost[x][y] + 1;
      vis[x-1][y] = 1;
    }
    
    if(isValid(x+1,y,n,m)&&!vis[x+1][y]){      
      qu.push({x+1,y});
      cost[x+1][y] = cost[x][y] + 1;
      vix[x+1][y] = 1;
    }
  }
 
  return maxx;
}
 
 
int32_t main(){
    
  fast;
  int n,m; cin >> n >> m;
  
  vector<pair<int,int>> vp;
 
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      char c; cin >> c;
      if(c=='.'){
        vp.pb({i,j});
        mat[i][j] = 1;
      }else{
        mat[i][j] = 0;
      } 
    }
  }
 
  int ans = 0;
 
  for(int i=0;i<vp.size();i++){
    int ct = bfs({vp[i].fi,vp[i].se},n,m);
    ans = max(ans,ct);
  }
 
  cout << ans;
 
  return 0;
}