#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(Graph& G, int sx, int sy, int w) {
  vector<int> dist(10000, -1);
  queue<int> que;
  int n = (sy * w) + sx;
  dist[n] = 0;
  que.push(n);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (auto nv : G[v]) {
      if (dist[nv] != -1) continue;
      dist[nv] = v + 1;
      que.push(nv);
    }
  }
  int res = 0;
  for (int i = 0; i < (1000); ++i) res = max(res, dist[i]);
  return res;
}
int h, w;
int solve() {
  cin >> h >> w;
  Graph G(h * w);
  vector<string> s(h + 1);
  for (int i = 0; i < (h); ++i) {
    string tmp;
    cin >> tmp;
    tmp.push_back('#');
    s[i] = tmp;
  }
  string tmp;
  for (int i = 0; i < (w); ++i) tmp.push_back('#');
  s[h] = tmp;
  for (int i = 0; i < (h); ++i)
    for (int j = 0; j < (w); ++j) {
      if (s[i][j] == '#') continue;
      int now = (i * w) + j;
      if (s[i + 1][j] != '#') {
        G[now].push_back(now + w);
        G[now + w].push_back(now);
      }
      if (s[i][j + 1] != '#') {
        G[now + 1].push_back(now);
        G[now].push_back(now + 1);
      }
    }
  int ans = 0;
  for (int i = 0; i < (h); ++i)
    for (int j = 0; j < (w); ++j) {
      if (s[i][j] == '#') continue;
      ans = max(ans, bfs(G, j, i, w));
    }
  cout << ans << endl;
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
  return 0;
}
