#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 18;
const long long MAX = 100005;
const long long MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
  return s << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1) s << "	";
  }
  return s;
}
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}
struct tup {
  long long first, second, th;
  tup(){};
  tup(long long a, long long b, long long c) : first(a), second(b), th(c){};
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);
  long long r, c;
  cin >> r >> c;
  vector<vector<string>> map(r + 2, vector<string>(c + 2));
  for (long long i = (0); i < (r); i++) {
    string tmp;
    cin >> tmp;
    for (long long j = (0); j < (tmp.length()); j++) {
      map[i + 1][j + 1] = tmp[j];
    }
  }
  long long res = 0;
  for (long long sh = (1); sh < (r + 1); sh++) {
    for (long long sw = (1); sw < (c + 1); sw++) {
      for (long long th = (1); th < (r + 1); th++) {
        for (long long tw = (1); tw < (c + 1); tw++) {
          vector<vector<long long>> score(r + 2, vector<long long>(c + 2, INF));
          if (map[sh][sw] == "." && map[th][tw] == ".") {
            queue<tup> q;
            q.push(tup(0, sh, sw));
            while (!q.empty()) {
              tup &now = q.front();
              if (now.first < score[now.second][now.th]) {
                score[now.second][now.th] = now.first;
                if (now.second != th || now.th != tw) {
                  if (map[now.second + 1][now.th] == ".") {
                    q.push(tup(now.first + 1, now.second + 1, now.th));
                  }
                  if (map[now.second - 1][now.th] == ".") {
                    q.push(tup(now.first + 1, now.second - 1, now.th));
                  }
                  if (map[now.second][now.th + 1] == ".") {
                    q.push(tup(now.first + 1, now.second, now.th + 1));
                  }
                  if (map[now.second][now.th - 1] == ".") {
                    q.push(tup(now.first + 1, now.second, now.th - 1));
                  }
                }
              }
              q.pop();
            }
            long long ans = score[th][tw];
            chmax(res, ans);
          }
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}
