#include <bits/stdc++.h>
const long long INF = 1000000007;
using namespace std;
using Graph = vector<vector<int>>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
int bfs(int v, vector<set<int>>& graph) {
  vector<int> dist(1000, -1);
  queue<int> que;
  dist[v] = 0;
  que.push(v);
  while (!que.empty()) {
    int now = que.front();
    que.pop();
    for (auto& next_v : graph[v]) {
      if (dist[next_v] != -1) continue;
      dist[next_v] = dist[now] + 1;
      que.push(next_v);
    }
  }
  int res = 0;
  for (int i = 0; i < (1000); ++i) {
    res = max(res, dist[i]);
  }
  return res;
}
int solve() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h + 1);
  for (int i = 0; i < (h); ++i) {
    string ss;
    cin >> ss;
    ss += '#';
    s[i] = ss;
  }
  string sss;
  for (int i = 0; i < (w); ++i) sss.push_back('#');
  s[h] = sss;
  vector<set<int>> graph(h * w);
  for (int i = 0; i < (h); ++i)
    for (int j = 0; j < (w); ++j) {
      int now = (i * w) + j;
      if (s[i][j] == '#') continue;
      if (i == h - 1 && j == w - 1) continue;
      if (j != w - 1 && i != h - 1) {
        if (s[i + 1][j] == '.' && s[i][j + 1] == '.') {
          graph[now].insert(now + w);
          graph[now + w].insert(now);
          graph[now].insert(now + 1);
          graph[now + 1].insert(now);
        }
      }
      if (s[i][j + 1] == '.') {
        graph[now].insert(now + 1);
        graph[now + 1].insert(now);
      }
      if (s[i + 1][j] == '.') {
        graph[now].insert(now + w);
        graph[now + w].insert(now);
      }
    }
  int ans = -INF;
  for (int i = 0; i < (h); ++i)
    for (int j = 0; j < (w); ++j) {
      if (s[i][j] == '#') continue;
      ans = max(ans, bfs((i * w) + j, graph));
    }
  cout << ans << endl;
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
  return 0;
}
