#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
bool chmax(T &a, const U &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
bool chmin(T &a, const U &b) {
  if (b < a) {
    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 h, w;
int calc = 0;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int bfs(vector<string> g, int st) {
  int maxdist = 0;
  vector<vector<bool>> vis(25, vector<bool>(25, false));
  queue<pair<int, int>> q;
  q.push({st, 0});
  vis[0][0] = true;
  while (!q.empty()) {
    int cur = q.front().first;
    int x = cur % w;
    int y = cur / w;
    int dist = q.front().second;
    q.pop();
    for (int i = 0, _i = (4); i < _i; ++i) {
      calc++;
      int nx = x + dx[i];
      int ny = y + dy[i];
      if ((0 <= nx && nx < w) && (0 <= ny && ny < h)) {
        if (vis[ny][nx] == false && g[ny][nx] == '.') {
          q.push({ny * w + nx, dist + 1});
          chmax(maxdist, dist + 1);
          vis[ny][nx] = true;
        }
      }
    }
  }
  return maxdist;
}
int main() {
  bool flag = false;
  long long ans = 0, sum = 0;
  cin >> h >> w;
  vector<string> g(h);
  for (int i = 0, _i = (h); i < _i; ++i) cin >> g[i];
  for (int i = 0, _i = (h); i < _i; ++i) {
    for (int j = 0, _i = (w); j < _i; ++j) {
      if (g[i][j] == '.') chmax(ans, bfs(g, i * w + j));
    }
  }
  cout << ans << endl;
  return 0;
}
