#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    cin >> s.at(i);
  }
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      int key = i * 100 + j;
      vector<vector<int>> dist(h, vector<int>(w, -1));
      queue<int> que;
      dist.at(i).at(j) = 0;
      que.push(key);
      while (!que.empty()) {
        int num = que.front();
        que.pop();
        if ((num / 100) > 0) {
          if (dist.at((num / 100) - 1).at(num % 100) == -1 &&
              s.at((num / 100) - 1)[num % 100] == '.') {
            dist.at((num / 100) - 1).at(num % 100) =
                dist.at(num / 100).at(num % 100) + 1;
            que.push(num - 100);
          }
        }
        if ((num / 100) < h - 1) {
          if (dist.at((num / 100) + 1).at(num % 100) == -1 &&
              s.at((num / 100) + 1)[num % 100] == '.') {
            dist.at((num / 100) + 1).at(num % 100) =
                dist.at(num / 100).at(num % 100) + 1;
            que.push(num + 100);
          }
        }
        if ((num % 100) > 0) {
          if (dist.at(num / 100).at((num % 100) - 1) == -1 &&
              s.at(num / 100)[(num % 100) - 1] == '.') {
            dist.at(num / 100).at((num % 100) - 1) =
                dist.at(num / 100).at(num % 100) + 1;
            que.push(num - 1);
          }
        }
        if ((num % 100) < w - 1) {
          if (dist.at(num / 100).at((num % 100) + 1) == -1 &&
              s.at(num / 100)[(num % 100) + 1] == '.') {
            dist.at(num / 100).at((num % 100) + 1) =
                dist.at(num / 100).at(num % 100) + 1;
            que.push(num + 1);
          }
        }
      }
      for (auto dist_ele : dist) {
        for (int dist_ele_ele : dist_ele) {
          if (dist_ele_ele > ans) {
            ans = dist_ele_ele;
          }
        }
      }
    }
  }
  cout << ans << endl;
}
