#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using ll = long long;
using namespace std;
const long long MOD = 1000000007;
const ll LINF = 1LL << 50;
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> maze(H + 2, vector<int>(W + 2, 1));
  for (int h = 0; h < (int)(H); h++) {
    for (int w = 0; w < (int)(W); w++) {
      char tmp;
      cin >> tmp;
      if (tmp == '.') maze[h + 1][w + 1] = 0;
    }
  }
  int ans = 0;
  for (int h = 0; h < (int)(H); h++) {
    for (int w = 0; w < (int)(W); w++) {
      if (maze[h + 1][w + 1] == 0) {
        vector<vector<int>> dist(H + 2, vector<int>(W + 2, 10000000));
        deque<vector<int>> dq;
        vector<int> tmp(2);
        tmp[0] = h + 1;
        tmp[1] = w + 1;
        dq.push_back(tmp);
        dist[tmp[0]][tmp[1]] = 0;
        while (!dq.empty()) {
          vector<int> next(2);
          vector<int> current(2);
          current = dq.front();
          dq.pop_front();
          ans = max({ans, dist[current[0]][current[1]]});
          next[0] = current[0] - 1;
          next[1] = current[1];
          if (maze[next[0]][next[1]] == 0) {
            if (dist[next[0]][next[1]] > dist[current[0]][current[1]] + 1) {
              dist[next[0]][next[1]] = dist[current[0]][current[1]] + 1;
              dq.push_back(next);
            }
          }
          next[0] = current[0] + 1;
          next[1] = current[1];
          if (maze[next[0]][next[1]] == 0) {
            if (dist[next[0]][next[1]] > dist[current[0]][current[1]] + 1) {
              dist[next[0]][next[1]] = dist[current[0]][current[1]] + 1;
              dq.push_back(next);
            }
          }
          next[0] = current[0];
          next[1] = current[1] - 1;
          if (maze[next[0]][next[1]] == 0) {
            if (dist[next[0]][next[1]] > dist[current[0]][current[1]] + 1) {
              dist[next[0]][next[1]] = dist[current[0]][current[1]] + 1;
              dq.push_back(next);
            }
          }
          next[0] = current[0];
          next[1] = current[1] + 1;
          if (maze[next[0]][next[1]] == 0) {
            if (dist[next[0]][next[1]] > dist[current[0]][current[1]] + 1) {
              dist[next[0]][next[1]] = dist[current[0]][current[1]] + 1;
              dq.push_back(next);
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
}
