#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
  ll H, W;
  cin >> H >> W;
  vector<vector<bool>> S(H, vector<bool>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char c;
      cin >> c;
      if (c == '#')
        S[i][j] = false;
      else
        S[i][j] = true;
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      vector<vector<int>> a(H, vector<int>(W, -1));
      vector<vector<int>> open;
      vector<int> start = {i, j, 0};
      open.push_back(start);
      while (open.size() > 0) {
        vector<int> node = open[0];
        open.erase(open.begin());
        if (node[0] > 0 && S[node[0] - 1][node[1]] &&
            a[node[0] - 1][node[1]] == -1)
          open.push_back(vector<int>{node[0] - 1, node[1], node[2] + 1});
        if (node[0] < H - 1 && S[node[0] + 1][node[1]] &&
            a[node[0] + 1][node[1]] == -1)
          open.push_back(vector<int>{node[0] + 1, node[1], node[2] + 1});
        if (node[1] > 0 && S[node[0]][node[1] - 1] &&
            a[node[0]][node[1] - 1] == -1)
          open.push_back(vector<int>{node[0], node[1] - 1, node[2] + 1});
        if (node[1] < W - 1 && S[node[0]][node[1] + 1] &&
            a[node[0]][node[1] + 1] == -1)
          open.push_back(vector<int>{node[0], node[1] + 1, node[2] + 1});
        a[node[0]][node[1]] = node[2];
        if (node[2] > ans) ans = node[2];
      }
    }
  }
  cout << ans << endl;
  return 0;
}
