#include <bits/stdc++.h>
using Int = int;
using namespace std;
template <class T>
T ant(const T &a, const T &b) {
  return a > b ? a : b;
};
template <class T>
T ont(const T &a, const T &b) {
  return a < b ? a : b;
};
template <class T>
void th(T &a, const T &b, T (*f)(const T &, const T &)) {
  a = f(a, b);
}
int four[] = {0, 1, 0, -1, 0};
int main() {
  int h, w;
  cin >> h >> w;
  std::vector<std::vector<char>> s(h, std::vector<char>(w));
  for (Int i = (0); i < (h); ++i)
    for (Int j = (0); j < (w); ++j) cin >> s[i][j];
  int max = 0;
  for (Int i = (0); i < (h); ++i)
    for (Int j = (0); j < (w); ++j) {
      vector<vector<int>> a(h, vector<int>(w, -1));
      a[i][j] = 0;
      queue<pair<int, int>> q;
      q.push(pair<int, int>(i, j));
      while (!q.empty()) {
        pair<int, int> next = q.front();
        for (Int k = (0); k < (4); ++k) {
          if (0 <= next.first + four[k] && next.first + four[k] < h &&
              0 <= next.second + four[k + 1] && next.second + four[k + 1] < w &&
              s[next.first + four[k]][next.second + four[k + 1]] == '.' &&
              a[next.first + four[k]][next.second + four[k + 1]] == -1) {
            th(max,
               a[next.first + four[k]][next.second + four[k + 1]] =
                   a[next.first][next.second] + 1,
               ant);
            q.push(pair<int, int>(next.first + four[k],
                                  next.second + four[k + 1]));
          }
        }
        q.pop();
      }
    }
  cout << max << endl;
}
