#include <bits/stdc++.h>
using namespace std;
using xy = pair<int, int>;
using Graph = vector<vector<xy>>;
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> S(H);
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char x;
      cin >> x;
      S.at(i).push_back(x);
    }
  }
  int dh[4] = {1, 0, -1, 0};
  int dw[4] = {0, 1, 0, -1};
  int Ans = -1;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S.at(i).at(j) != '#') {
        vector<vector<int>> d(H, vector<int>(W, -1));
        queue<xy> que;
        d.at(i).at(j) = 0;
        xy p = make_pair(i, j);
        que.push(p);
        int An = 0;
        while (!que.empty()) {
          p = que.front();
          que.pop();
          for (int k = 0; k < 4; i++) {
            int nh = p.first + dh[k];
            int nw = p.second + dw[k];
            if (nh < 0 || nh >= H || nw < 0 || nw >= W) {
              continue;
            }
            if (S.at(nh).at(nw) == '#') {
              continue;
            }
            if (d.at(nh).at(nw) >= 0) {
              continue;
            }
            d.at(nh).at(nw) = d.at(p.first).at(p.second) + 1;
            An = d.at(nh).at(nw);
            que.push(make_pair(nh, nw));
          }
        }
        if (An > Ans) {
          Ans = An;
        }
      }
    }
  }
  cout << Ans << endl;
}
