#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
const int INF = INT_MAX - 5;
char mt[30][30];
int vis[30][30];
int dx[4] = {-1, 0, 0, 1};
int dy[4] = {0, -1, 1, 0};
int main() {
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; ++i) {
    for (int k = 0; k < w; ++k) {
      cin >> mt[i][k];
    }
  }
  int ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int k = 0; k < w; ++k) {
      for (int j = 0; j < h; ++j) {
        for (int l = 0; l < w; ++l) {
          vis[j][l] = INF;
        }
      }
      queue<ii> q;
      q.emplace(i, k);
      vis[i][k] = 0;
      while (!q.empty()) {
        auto f = q.front();
        q.pop();
        int d = vis[f.first][f.second];
        for (int j = 0; j < 4; ++j) {
          int px = dx[j] + f.first;
          int py = dy[j] + f.second;
          if (px >= 0 and px < h and py >= 0 and py < w) {
            if (mt[px][py] == '.') {
              if (d + 1 < vis[px][py]) {
                vis[px][py] = d + 1;
                q.emplace(px, py);
              }
            }
          }
        }
      }
      int mx = 0;
      for (int j = 0; j < h; ++j) {
        for (int l = 0; l < w; ++l) {
          if (mt[j][l] == '.' and vis[j][l] != INF) {
            mx = max(mx, vis[j][l]);
          }
        }
      }
      ans = max(ans, mx);
    }
  }
  cout << ans << endl;
  return 0;
}
