#include <bits/stdc++.h>
using namespace std;
vector<vector<bool> > M;
int h, w;
int bfs(int sy, int sx) {
  vector<vector<int> > dist(h + 2, vector<int>(w + 2));
  for (int i = 0; i < h + 2; i++) {
    for (int j = 0; j < w + 2; j++) {
      dist[i][j] = -1;
    }
  }
  queue<pair<int, int> > que;
  que.push(make_pair(sy, sx));
  dist[sy][sx] = 0;
  vector<int> dy = {-1, 0, 1, 0};
  vector<int> dx = {0, 1, 0, -1};
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    int y = p.first;
    int x = p.second;
    for (int i = 0; i < 4; i++) {
      if (M[y + dy[i]][x + dx[i]] &&
          (dist[y + dy[i]][x + dx[i]] > dist[y][x] + 1 ||
           dist[y + dy[i]][x + dx[i]] == -1)) {
        que.push(make_pair(y + dy[i], x + dx[i]));
        dist[y + dy[i]][x + dx[i]] = dist[y][x] + 1;
      }
    }
  }
  int ans = -1;
  for (int i = 0; i < h + 2; i++) {
    for (int j = 0; j < w + 2; j++) {
      ans = max(ans, dist[i][j]);
    }
  }
  return ans;
}
void solver() {
  cin >> h >> w;
  vector<bool> line1(w);
  M.push_back(line1);
  for (int i = 0; i < h; i++) {
    vector<bool> m;
    m.push_back(false);
    string s;
    cin >> s;
    for (int j = 0; j < w; j++) {
      if (s[j] == '.')
        m.push_back(true);
      else
        m.push_back(false);
    }
    m.push_back(false);
    M.push_back(m);
  }
  vector<bool> line2(w);
  M.push_back(line2);
  int ans = -1;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (M[i + 1][j + 1]) ans = max(ans, bfs(i + 1, j + 1));
    }
  }
  cout << ans << "\n";
}
int main() { solver(); }
