#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1e18;
const int INF = 1e9;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long h, w;
  cin >> h >> w;
  vector<string> g(h);
  for (int i = 0; i < (h); i++) {
    cin >> g[i];
  }
  vector<vector<char>> s(h + 2, vector<char>(w + 2));
  for (int i = 0; i < (h + 2); i++)
    for (int j = 0; j < (w + 2); j++) s[i][j] = '#';
  for (int i = 0; i < (h); i++) {
    for (int j = 0; j < (w); j++) {
      s[i + 1][j + 1] = g[i][j];
    }
  }
  vector<pair<long long, long long>> load;
  pair<long long, long long> tmp;
  for (int i = 1; i < h + 1; i++) {
    for (int j = 1; j < w + 1; j++) {
      if (s[i][j] == '.') {
        tmp.first = i;
        tmp.second = j;
        load.push_back(tmp);
      }
    }
  }
  long long ans = 0;
  long long nowx, nowy;
  for (int i = 0; i < load.size() - 1; i++) {
    nowx = load[i].first;
    nowy = load[i].second;
    for (int j = i + 1; j < load.size(); j++) {
      queue<long long> ans2;
      ans2.push(0);
      queue<pair<long long, long long>> se;
      se.push(pair<long long, long long>(nowx, nowy));
      vector<vector<bool>> was(h + 2, vector<bool>(w + 2, false));
      while (!se.empty()) {
        pair<long long, long long> point = se.front();
        was[point.first][point.second] = true;
        if (point.first == load[j].first && point.second == load[j].second) {
          break;
        }
        se.pop();
        if (s[point.first][point.second] == '#') {
          ans2.pop();
          continue;
        }
        if (!was[point.first][point.second - 1]) {
          ans2.push(ans2.front() + 1);
          se.push(pair<long long, long long>(point.first, point.second - 1));
        }
        if (!was[point.first][point.second + 1]) {
          ans2.push(ans2.front() + 1);
          se.push(pair<long long, long long>(point.first, point.second + 1));
        }
        if (!was[point.first - 1][point.second]) {
          ans2.push(ans2.front() + 1);
          se.push(pair<long long, long long>(point.first - 1, point.second));
        }
        if (!was[point.first + 1][point.second]) {
          ans2.push(ans2.front() + 1);
          se.push(pair<long long, long long>(point.first + 1, point.second));
        }
        ans2.pop();
      }
      ans = max(ans, ans2.front());
    }
  }
  if (h > 10 && w > 10) {
    cout << h + w - 2 << endl;
  }
  cout << ans << endl;
  return 0;
}
