#include <iostream>
#include <queue>

using namespace std;

#define rep(i,n) for(int i=0; i<(int)(n); i++)

int h, w;
char a[22][22];
int b[22][22];

int bfs(int sh, int sw) {
  int d[5] = {0, -1, 0, 1, 0};
  rep(i,h) rep(j,w) b[i+1][j+1] = - (a[i+1][j+1] == '.');
  b[sh][sw] = 0;
  
  queue<pair<int, int> > q;
  q.push(make_pair(sh, sw));
  while(!q.empty()) {
    pair<int, int> p = q.front(); q.pop();
    int ph = p.first, pw = p.second;
    rep(i,4) {
      int nh = ph + d[i], nw = pw + d[i+1];
      if(b[nh][nw] == -1) {
        b[nh][nw] = b[ph][pw] + 1;
        q.push(make_pair(nh, nw));
      }
    }
  }
  
  int m = 0;
  rep(i,h) rep(j,w) m = max(m, b[i+1][j+1]);
  return m;
}

int main() {
  cin >> h >> w;
  rep(i,h) rep(j,w) cin >> a[i+1][j+1];
  
  int m = 0;
  rep(i,h) rep(j,w) if(a[i+1][j+1] == '.') m = max(m, bfs(i+1,j+1));
  cout << m << endl;
  return 0;
}