#include <bits/stdc++.h>
using namespace std;
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++) {
      char c;
      cin >> c;
      S.at(i).at(j) = c;
    }
  }
  int max = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S.at(i).at(j) == '#') continue;
      vector<vector<int>> A(H, vector<int>(W, -1));
      queue<pair<int, int>> que;
      que.push(make_pair(i, j));
      while (que.size()) {
        pair<int, int> tugi = que.front();
        que.pop();
        int thisx = tugi.first;
        int thisy = tugi.second;
        if (thisx - 1 >= 0) {
          if (A.at(thisx - 1).at(thisy) == -1 &&
              S.at(thisx - 1).at(thisy) != '#') {
            A.at(thisx - 1).at(thisy) = A.at(thisx).at(thisy) + 1;
            if (max <= A.at(thisx).at(thisy) + 1)
              max = A.at(thisx).at(thisy) + 1;
            que.push(make_pair(thisx - 1, thisy));
          }
        }
        if (thisx + 1 < S.size()) {
          if (A.at(thisx + 1).at(thisy) == -1 &&
              S.at(thisx + 1).at(thisy) != '#') {
            A.at(thisx + 1).at(thisy) = A.at(thisx).at(thisy) + 1;
            if (max <= A.at(thisx).at(thisy) + 1)
              max = A.at(thisx).at(thisy) + 1;
            que.push(make_pair(thisx + 1, thisy));
          }
        }
        if (thisy - 1 >= 0) {
          if (A.at(thisx).at(thisy - 1) == -1 &&
              S.at(thisx).at(thisy - 1) != '#') {
            A.at(thisx).at(thisy - 1) = A.at(thisx).at(thisy) + 1;
            if (max <= A.at(thisx).at(thisy) + 1)
              max = A.at(thisx).at(thisy) + 1;
            que.push(make_pair(thisx, thisy - 1));
          }
        }
        if (thisy + 1 < S.at(0).size()) {
          if (A.at(thisx).at(thisy + 1) == -1 &&
              S.at(thisx).at(thisy + 1) != '#') {
            A.at(thisx).at(thisy + 1) = A.at(thisx).at(thisy) + 1;
            if (max <= A.at(thisx).at(thisy) + 1)
              max = A.at(thisx).at(thisy) + 1;
            que.push(make_pair(thisx, thisy + 1));
          }
        }
      }
    }
  }
  cout << max + 1;
}
