#include <bits/stdc++.h>
using namespace std;
int main() {
  long long h, w;
  std::cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) {
    std::cin >> s[i];
  }
  unordered_map<long long, map<long long, long long>> dist;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') continue;
      if (i + 1 < h && s[i + 1][j] == '.') {
        dist[i + 100 * j][i + 1 + j * 100] = 1;
      }
      if (i - 1 >= 0 && s[i - 1][j] == '.') {
        dist[i + 100 * j][i - 1 + j * 100] = 1;
      }
      if (j + 1 < w && s[i][j + 1] == '.') {
        dist[i + 100 * j][i + 100 * (j + 1)] = 1;
      }
      if (j - 1 >= 0 && s[i][j - 1] == '.') {
        dist[i + 100 * j][i + 100 * (j - 1)] = 1;
      }
    }
  }
  for (int ii = 0; ii < h; ii++) {
    for (int jj = 0; jj < w; jj++) {
      for (int iii = 0; iii < h; iii++) {
        for (int jjj = 0; jjj < w; jjj++) {
          if (dist[ii + 100 * jj][iii + jjj * 100] == 0) {
            dist[ii + jj * 100][iii + jjj * 100] = (long long)1e10;
          }
        }
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      for (int ii = 0; ii < h; ii++) {
        for (int jj = 0; jj < w; jj++) {
          for (int iii = 0; iii < h; iii++) {
            for (int jjj = 0; jjj < w; jjj++) {
              dist[ii + jj * 100][iii + jjj * 100] =
                  min(dist[ii + jj * 100][iii + jjj * 100],
                      dist[ii + jj * 100][i + j * 100] +
                          dist[i + j * 100][iii + jjj * 100]);
            }
          }
        }
      }
    }
  }
  for (int ii = 0; ii < h; ii++) {
    for (int jj = 0; jj < w; jj++) {
      for (int iii = 0; iii < h; iii++) {
        for (int jjj = 0; jjj < w; jjj++) {
          if (dist[ii + jj * 100][iii + jjj * 100] != (long long)1e10) {
            ans = max(ans, dist[ii + jj * 100][iii + jjj * 100]);
          }
        }
      }
    }
  }
  std::cout << ans << std::endl;
}
