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

int main()
{
  int h, w;
  cin >> h >> w;
  vector<string> f;
  for (int i=0; i<h; i++) {
    string l; cin >> l;
    f.push_back(l);
  }

  int ans = 0;
  int dx[] = {1, -1, 0, 0};
  int dy[] = {0, 0, 1, -1};
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      if (f[i][j]=='#') continue;

      vector<vector<int>> vd(h, vector<int>(w, -1));
      queue<pair<int, int>> q;
      q.push(make_pair(j, i));
      vd[i][j] = 0;
      while(!q.empty()) {
        int nx, ny;
        pair<int, int> np = q.front(); q.pop();
        nx = np.first;
        ny = np.second;
        for (int k=0; k<4; k++) {
          int tx = nx + dx[k];
          int ty = ny + dy[k];
          if (tx<0||w<=tx||ty<0||h<=ty) continue;
          if (vd[ty][tx]>=0||f[ty][tx]=='#') continue;
          q.push(make_pair(tx, ty));
          vd[ty][tx] = vd[ny][nx]+1;
          ans = max(ans, vd[ty][tx]);
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}
