#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
using namespace std;

void solve(){
  int h, w, ans = 0; cin >> h >> w;
  char c[h][w];
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> c[i][j];
    }
  }
  int x[4] = {1, -1, 0, 0}, y[4] = {0, 0, 1, -1};
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(c[i][j] == '.'){
        queue<pair<int, int> > q;
        q.push(make_pair(i, j));
        bool visited[h][w] = {false};
        visited[i][j] = true;
        int dis[h][w];
        dis[i][j] = 0;
        while(q.size() > 0){
          int px = q.front().first, py = q.front().second;
          q.pop();
          //cout << "(" << px << "," << py << ") -> ";
          for(int k = 0; k < 4; k++){
            int nx = px + x[k], ny = py + y[k];
            if(nx >= 0 && nx <= h - 1 && ny >= 0 && ny <= w - 1 && visited[nx][ny] == false && c[nx][ny] == '.'){
              //cout << "(" << nx << "," << ny << ") , ";
              visited[nx][ny] = true;
              dis[nx][ny] = dis[px][py] + 1;
              ans = max(ans, dis[nx][ny]);
              q.push(make_pair(nx, ny));
            }
          }
          //cout << endl;
        }
      }
    }
  }
  cout << ans << endl;
  return;
}

int main(){
  solve();
  return 0;
}
