#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define int ll

typedef queue<pair<int,int>> Q;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
inline int in() {int x; cin >> x; return x;}
const int INF = 1e+9;

int h, w;
vs s;
int dirh = {0,-1,0,+1}, dirw = {-1,0,+1,0};
int ans = 0;

void bfs(int h1, int w1) {
  vvi dist(h, vi(w, INF));
  Q q;
  q.push({h1,w1})
  while (!q.empty()) {
    int h2, w2; tie(h2,w2) = q.front; q.pop();
    FOR (d,0,4) {
      int h3 = h2 + dirh[d];
      int w3 = w2 + dirw[d];

      if (!(0<=h3 && h3<=h && 0<=w3 && w3<=w)) continue;
      if (s[h3][w3]=='#') continue;
      if (dist[h3][w3]!=INF) continue;

      dist[h3][w3] = dist[q2][q2] + 1;
      q.push({h3,w3});
    }
  }

  FOR (i,0,h) {
    FOR (j,0,w) {
      if (dist[i][j]==INF) continue;
      ans = max(ans, dist[i][j]);
    }
  }
}
void solve() {
  h = in();
  w = in();
  s.resize(h);
  FOR (i,0,h) cin >> s[h];

  FOR (i,0,h) {
    FOR (j,0,w) {
      if (s[i][j]=='#') continue;
      bfs(i,j);
    }
  }

  cout << ans << endl;
}

#undef int
int main() {
  solve();
}