#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  char get;
  vector<vector<bool>> table(h, vector<bool>(w, false));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> get;
      if (get == '.') table[i][j] = true;
    }
  }
  int maximum = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      vector<vector<bool>> is_visit(h, vector<bool>(w, false));
      vector<vector<int>> distance(h, vector<int>(w, 0));
      is_visit[i][j] = true;
      pair<int, int> s = make_pair(i, j);
      queue<pair<int, int>> q;
      q.push(s);
      distance[i][j] = 0;
      while (!q.empty()) {
        pair<int, int> a = q.front();
        maximum = max(maximum, distance[a.first][a.second]);
        q.pop();
        if (a.first > 0)
          if (table[a.first - 1][a.second])
            if (!is_visit[a.first - 1][a.second]) {
              is_visit[a.first - 1][a.second] = true;
              distance[a.first - 1][a.second] = distance[a.first][a.second] + 1;
              q.push(make_pair(a.first - 1, a.second));
            }
        if (a.second > 0)
          if (table[a.first][a.second - 1])
            if (!is_visit[a.first][a.second - 1]) {
              is_visit[a.first][a.second - 1] = true;
              distance[a.first][a.second - 1] = distance[a.first][a.second] + 1;
              q.push(make_pair(a.first, a.second - 1));
            }
        if (a.first < h - 1)
          if (table[a.first + 1][a.second])
            if (!is_visit[a.first + 1][a.second]) {
              is_visit[a.first + 1][a.second] = true;
              distance[a.first + 1][a.second] = distance[a.first][a.second] + 1;
              q.push(make_pair(a.first + 1, a.second));
            }
        if (a.second < w - 1)
          if (table[a.first][a.second + 1])
            if (!is_visit[a.first][a.second + 1]) {
              is_visit[a.first][a.second + 1] = true;
              distance[a.first][a.second + 1] = distance[a.first][a.second] + 1;
              q.push(make_pair(a.first, a.second + 1));
            }
      }
    }
  }
  cout << maximum << endl;
  return 0;
}
