#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void CHMAX(T& a, const T b) {
  if (a < b) a = b;
}
template <typename T>
inline void CHMIN(T& a, const T b) {
  if (a > b) a = b;
}
constexpr long long MOD = 1000000007ll;
const double EPS = 1e-11;
int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  char s[30][30];
  for (int i = 0; i < (w + 2); ++i) {
    s[0][i] = s[h + 1][i] = '#';
  }
  for (int i = 0; i < (h + 2); ++i) {
    s[i][0] = s[i][w + 1] = '#';
  }
  for (int i = 0; i < (h); ++i) {
    for (int j = 0; j < (w); ++j) {
      cin >> s[i + 1][j + 1];
    }
  }
  int ans = 0;
  for (int x = (1); x < (h + 1); ++x) {
    for (int y = (1); y < (w + 1); ++y) {
      if (s[x][y] == '#') {
        continue;
      }
      for (int a = (1); a < (h + 1); ++a) {
        for (int b = (1); b < (w + 1); ++b) {
          if (s[a][b] == '#') {
            continue;
          }
          bool used[30][30];
          int d[30][30];
          for (int i = (1); i < (h + 1); ++i) {
            for (int j = (1); j < (w + 1); ++j) {
              used[i][j] = false;
            }
          }
          used[x][y] = true;
          d[x][y] = 0;
          queue<pair<int, int> > que;
          que.push(pair<int, int>(x, y));
          while (que.size()) {
            pair<int, int> uv = que.front();
            que.pop();
            int u = uv.first, v = uv.second;
            if (u == a && v == b) {
              break;
            }
            for (int i = 0; i < (4); ++i) {
              int uu = u + dx[i], vv = v + dy[i];
              if (s[uu][vv] == '#' || used[uu][vv]) {
                continue;
              }
              que.push(pair<int, int>(uu, vv));
              d[uu][vv] = d[u][v] + 1;
            }
          }
          CHMAX(ans, d[a][b]);
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
