#include <bits/stdc++.h>
const int INF = 2147483647;
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};
int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> maze(h + 2, vector<char>(w + 2, '#'));
  for (long long i = (1); i < (h + 1); i++)
    for (long long j = (1); j < (w + 1); j++) cin >> maze[i][j];
  int res = 0;
  for (long long i = (1); i < (h + 1); i++) {
    for (long long j = (1); j < (w + 1); j++) {
      if (maze[i][j] == '#') continue;
      int dist = 0;
      vector<vector<int>> seen(h + 2, vector<int>(w + 2, -1));
      seen[i][j] = 0;
      queue<pair<P, int>> que;
      que.push(make_pair(make_pair(i, j), 0));
      while (!que.empty()) {
        auto q = que.front();
        que.pop();
        dist = max(dist, q.second);
        seen[q.first.first][q.first.second] = q.second;
        for (int k = 0; k < 4; k++) {
          if (maze[q.first.first + dx[k]][q.first.second + dy[k]] != '#') {
            if (seen[q.first.first + dx[k]][q.first.second + dy[k]] == -1) {
              que.push(make_pair(
                  make_pair(q.first.first + dx[k], q.first.second + dy[k]),
                  q.second + 1));
            }
          }
        }
      }
      res = max(res, dist);
    }
  }
  cout << res << endl;
  return 0;
}
