#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s.at(i).at(j);
    }
  }
  int dx[4] = {1, -1, 0, 0};
  int dy[4] = {0, 0, 1, -1};
  using P = pair<int, int>;
  int max_dist = 0;
  for (int sy = 0; sy < h; sy++) {
    for (int sx = 0; sx < w; sx++) {
      for (int gy = 0; gy < h; gy++) {
        for (int gx = 0; gx < w; gx++) {
          vector<vector<int>> d(h, vector<int>(w, 1000));
          queue<P> que;
          que.push(P(sy, sx));
          d.at(sy).at(sx) = 0;
          while (!que.empty()) {
            P pos = que.front();
            que.pop();
            if (pos.first == gy && pos.second == gx) break;
            for (int i = 0; i < 4; i++) {
              int ny = pos.first + dy[i];
              int nx = pos.second + dx[i];
              if (0 <= ny && ny < h && 0 <= nx && nx < w &&
                  s.at(ny).at(nx) != '#' && d.at(ny).at(nx) == 1000) {
                que.push(P(ny, nx));
                d.at(ny).at(nx) = d.at(pos.first).at(pos.second) + 1;
              }
            }
          }
          if (d.at(gy).at(gx) == 1000) continue;
          max_dist = max(max_dist, d.at(gy).at(gx));
        }
      }
    }
  }
  cout << max_dist << endl;
}
