#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template <class T>
inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  cin.tie(0), ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < int(h); i++) cin >> s[i];
  int ans = 0;
  for (int i = 0; i < int(h); i++) {
    for (int j = 0; j < int(w); j++) {
      vector<vector<char>> tmp(h + 2, vector<char>(w + 2, '#'));
      for (int a = 0; a < int(h); a++)
        for (int b = 0; b < int(w); b++) tmp[a + 1][b + 1] = s[a][b];
      if (tmp[i + 1][j + 1] == '.') {
        queue<pair<int, int>> q;
        q.push({i + 1, j + 1});
        vector<vector<int>> cnt(h, vector<int>(w));
        while (!q.empty()) {
          pair<int, int> p = q.front();
          q.pop();
          int x = p.second, y = p.first;
          for (int k = 0; k < int(4); k++) {
            if (tmp[y + dy[k]][x + dx[k]] == '.') {
              cnt[y + dy[k] - 1][x + dx[k] - 1] += cnt[y - 1][x - 1] + 1;
              tmp[y + dy[k]][x + dx[k]] = '#';
              q.push({y + dy[k], x + dx[k]});
            }
          }
        }
        for (int a = 0; a < int(h); a++)
          for (int b = 0; b < int(w); b++) chmax(ans, cnt[a][b]);
      }
    }
  }
  cout << ans;
  cout << "\n";
  return 0;
}
