#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const ll INF = 100100100100;
const int MOD = 1000000007;
int H, W;
vector<string> field;
vector<vector<int>> dist;
queue<P> que;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
  cin >> H >> W;
  field.resize(H);
  for (int h = 0; h < H; ++h) cin >> field[h];
  int ans = -1;
  for (int i = 0; i < (int)H; i++)
    for (int j = 0; j < (int)W; j++) {
      dist = vector<vector<int>>(H, vector<int>(W, -1));
      dist[i][j] = 0;
      queue<P>().swap(que);
      que.push(P(i, j));
      while (!que.empty()) {
        P v = que.front();
        que.pop();
        int h, w;
        tie(h, w) = v;
        for (int dir = 0; dir < (int)4; dir++) {
          int nh = h + dx[dir];
          int nw = w + dy[dir];
          if (field[nh][nw] == '#') continue;
          if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
          if (dist[nh][nw] != -1) continue;
          dist[nh][nw] = dist[h][w] + 1;
          que.push(P(nh, nw));
        }
      }
      int cmax = -1;
      for (int i = 0; i < (int)H; i++)
        for (int j = 0; j < (int)W; j++) {
          if (dist[i][j] > cmax) cmax = dist[i][j];
        }
      if (cmax > ans) ans = cmax;
    }
  cout << ans << endl;
  return 0;
}
