#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int di[] = {0,1,0,-1};
int dj[] = {1,0,-1,0};
int main() {

  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  
  int ans = 0;
  rep(i,h)rep(j,w) {
    queue<P> q;
    vector<vector<int>> d(h,vector<int>(w,100000));
    
    auto push = [&](int x, int y, int val) {
      if (x<0||h<=x||y<0||w<=y||d[x][y]!=100000||s[x][y]!='.') {
        return;
      }
      q.emplace(x,y);
      d[x][y] = val;
      ans = max(ans,val);
    };

    push(i,j,0);
    while ( !q.empty() ) {
      P p = q.front();
      int x = p.first, y = p.second;
      q.pop();
      rep(dir,4) push(x+di[dir],y+dj[dir],d[x][y]+1);
    }
  }
  cout << ans << endl;
}
