#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const int MOD = 1000000000 + 7;
template <typename tuple<long long, long long, long long>>
inline string toString(const tuple<long long, long long, long long> &a) {
  ostringstream oss;
  oss << a;
  return oss.str();
};
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> maze(H);
  for (int i = 0; i < (H); i++) cin >> maze[i];
  int mx = 0;
  for (int i = 0; i < (H); i++) {
    for (int j = 0; j < (W); j++) {
      if (maze[i][j] == '#') continue;
      vector<vector<int>> dist(H, vector<int>(W, 0));
      vector<vector<bool>> done(H, vector<bool>(W, false));
      queue<pair<int, int>> qu;
      qu.push(pair<int, int>(i, j));
      while (!qu.empty()) {
        int y = qu.front().first, x = qu.front().second;
        qu.pop();
        for (int k = 0; k < (4); k++) {
          int ny = y + dy[k], nx = x + dx[k];
          if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
          if (maze[ny][nx] == '.' && !done[ny][nx]) {
            done[ny][nx] = true;
            dist[ny][nx] = dist[y][x] + 1;
            qu.push(pair<int, int>(ny, nx));
          }
        }
      }
      int cnt = 0;
      for (int a = 0; a < (H); a++) {
        for (int b = 0; b < (W); b++) {
          cnt = max(cnt, dist[a][b]);
        }
      }
      mx = max(mx, cnt);
    }
  }
  cout << mx << endl;
}
