#include <bits/stdc++.h>
using namespace std;
int h, w;
int id(int i, int j) { return i * w + j; }
int main() {
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; ++i) cin >> s[i];
  int d[h * w][h * w];
  for (int i = 0; i < h * w; ++i)
    for (int j = 0; j < h * w; ++j) d[i][j] = 100000;
  if (h == 1) {
    for (int i = 0; i < h; ++i)
      for (int j = 0; j < w; ++j) {
        if (s[i][j] == '.') {
          if (j == 0) {
            if (s[i][j + 1] == '.') d[id(i, j)][id(i, j) + 1] = 1;
          } else if (j == w - 1) {
            if (s[i][j - 1] == '.') d[id(i, j)][id(i, j) - 1] = 1;
          } else {
            if (s[i][j + 1] == '.') d[id(i, j)][id(i, j) + 1] = 1;
            if (s[i][j - 1] == '.') d[id(i, j)][id(i, j) - 1] = 1;
          }
        }
      }
  } else if (w == 1) {
    cout << h - 1 << endl;
    return 0;
  } else {
    for (int i = 0; i < h; ++i)
      for (int j = 0; j < w; ++j) {
        if (s[i][j] == '.') {
          if (i == 0 && j == 0) {
            if (s[i][j + 1] == '.') d[id(i, j)][id(i, j) + 1] = 1;
            if (s[i + 1][j] == '.') d[id(i, j)][id(i, j) + w] = 1;
          } else if (i == 0 && j == w - 1) {
            if (s[i + 1][j] == '.') d[id(i, j)][id(i, j) + w] = 1;
            if (s[i][j - 1] == '.') d[id(i, j)][id(i, j) - 1] = 1;
          } else if (i == 0) {
            if (s[i][j + 1] == '.') d[id(i, j)][id(i, j) + 1] = 1;
            if (s[i + 1][j] == '.') d[id(i, j)][id(i, j) + w] = 1;
            if (s[i][j - 1] == '.') d[id(i, j)][id(i, j) - 1] = 1;
          } else if (i == h - 1 && j == 0) {
            if (s[i - 1][j] == '.') d[id(i, j)][id(i, j) - w] = 1;
            if (s[i][j + 1] == '.') d[id(i, j)][id(i, j) + 1] = 1;
          } else if (i == h - 1 && h == w - 1) {
            if (s[i - 1][j] == '.') d[id(i, j)][id(i, j) - w] = 1;
            if (s[i][j - 1] == '.') d[id(i, j)][id(i, j) - 1] = 1;
          } else if (i == h - 1) {
            if (s[i - 1][j] == '.') d[id(i, j)][id(i, j) - w] = 1;
            if (s[i][j + 1] == '.') d[id(i, j)][id(i, j) + 1] = 1;
            if (s[i][j - 1] == '.') d[id(i, j)][id(i, j) - 1] = 1;
          } else if (j == 0) {
            if (s[i - 1][j] == '.') d[id(i, j)][id(i, j) - w] = 1;
            if (s[i][j + 1] == '.') d[id(i, j)][id(i, j) + 1] = 1;
            if (s[i + 1][j] == '.') d[id(i, j)][id(i, j) + w] = 1;
          } else if (j == w - 1) {
            if (s[i - 1][j] == '.') d[id(i, j)][id(i, j) - w] = 1;
            if (s[i + 1][j] == '.') d[id(i, j)][id(i, j) + w] = 1;
            if (s[i][j - 1] == '.') d[id(i, j)][id(i, j) - 1] = 1;
          } else {
            if (s[i - 1][j] == '.') d[id(i, j)][id(i, j) - w] = 1;
            if (s[i][j + 1] == '.') d[id(i, j)][id(i, j) + 1] = 1;
            if (s[i + 1][j] == '.') d[id(i, j)][id(i, j) + w] = 1;
            if (s[i][j - 1] == '.') d[id(i, j)][id(i, j) - 1] = 1;
          }
        }
      }
  }
  for (int i = 0; i < h * w; ++i)
    for (int j = 0; j < h * w; ++j)
      for (int k = 0; k < h * w; ++k) d[j][k] = min(d[j][i] + d[i][k], d[j][k]);
  int ans = -1;
  for (int i = 0; i < h * w; ++i)
    for (int j = 0; j < h * w; ++j) {
      if (s[i / w][i % w] == '.' && s[j / w][j % w] == '.')
        ans = max(ans, d[i][j]);
    }
  cout << ans << endl;
}
