#include<bits/stdc++.h>

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int h,w;
char c[30][30];

int mx[] = {-1,0,0,1};
int my[] = {0,1,-1,0};

int LongestDistance(int sx,int sy){
  int ret = 0;
  queue<tuple<int,int,int>> que;
  que.emplace(sx,sy,0);
  bitset<30> visited[30];
  while(!que.empty()){
    auto [x,y,d] = que.front();
    que.pop();
    if(visited[y][x])continue;
    visited[y][x] = 1;
    ChangeMax(ret,d);
    for(int i = 0; i < 4; ++i){
      auto [nx,ny,nd] = make_tuple(x+mx[i],y+my[i],d+1);
      if(clamp(nx,0,w-1)!=nx || clamp(ny,0,h-1)!=ny)continue;
      if(c[ny][nx] == '#')continue;
      que.emplace(nx,ny,nd);
    }
  }
  return ret;
}

int main(){
  cin >> h >> w;
  for(int i = 0; i < h; ++i)
    for(int j = 0; j < w; ++j)
      cin >> c[i][j];
  int ans = 0;
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      ChangeMax(ans,LongestDistance(j,i));
    }
  }
  cout << ans << endl;

  return 0;
}
