#include <bits/stdc++.h>
using namespace std;
bool m[30][30];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c;
      cin >> c;
      if (c == '.') m[i + 1][j + 1] = 1;
    }
  }
  int ans = 0;
  auto s = [&](int x, int y) {
    queue<int> xq, yq;
    xq.push(x);
    yq.push(y);
    vector<vector<int>> d(h + 1, vector<int>(w + 1, 1e9));
    d[x][y] = 0;
    while (!xq.empty()) {
      int i = xq.front(), j = yq.front();
      xq.pop(), yq.pop();
      for (int t = 0; t < 4; t++) {
        if (m[i + dx[t]][j + dy[t]] && d[i + dx[t]][j + dy[t]] > d[i][j] + 1) {
          ans = max(ans, d[i][j] + 1);
          d[i + dx[t]][j + dy[t]] = d[i][j] + 1;
          xq.push(i + dx[t]), yq.push(j + dy[t]);
        }
      }
    }
  };
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      s(i + 1, j + 1);
    }
  }
  cout << ans << "\n";
  return 0;
}
