#include <bits/stdc++.h>
using namespace std;
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;
}
using ll = long long;
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9 = 1000000000;
const ll mod = 1000000007;
int h, w;
vector<string> board;
int solve() {
  int ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (board[i][j] != '.') continue;
      vector<vector<int>> m(h, vector<int>(w, 0));
      queue<pair<int, int>> que;
      que.push(pair<int, int>(i, j));
      while (!que.empty()) {
        pair<int, int> now = que.front();
        que.pop();
        int x = now.first;
        int y = now.second;
        for (int k = 0; k < 4; ++k) {
          int nx = x + dx[k];
          int ny = y + dy[k];
          if (nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
          if (board[nx][ny] == '#') continue;
          if (m[nx][ny] == 0) {
            chmax(m[nx][ny], m[x][y] + 1);
            que.push(pair<int, int>(nx, ny));
            ans = max(ans, m[nx][ny]);
          }
        }
      }
    }
  }
  return ans;
}
int main() {
  cin >> h >> w;
  board.resize(h);
  for (int i = 0; i < h; ++i) cin >> board[i];
  cout << solve() << endl;
}
