#include <bits/stdc++.h>
using namespace std;
int inf = 2147483647;
int64_t inf64 = 9223372036854775807;
int MOD = 1e+7;
const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<string> grid(H);
  for (int h = 0; h < H; h++) cin >> grid[h];
  int res = -1;
  for (int sh = 0; sh < H; sh++) {
    for (int sw = 0; sw < W; sw++) {
      queue<pair<int, int>> que;
      vector<vector<int>> dist(H, vector<int>(W, -1));
      dist[sh][sw] = 0;
      que.push({sh, sw});
      while (!que.empty()) {
        int vh = que.front().first;
        int vw = que.front().second;
        que.pop();
        for (int dir = 0; dir < 4; dir++) {
          int nvh = vh + dy[dir];
          int nvw = vw + dx[dir];
          if (nvh < 0) continue;
          if (nvw < 0) continue;
          if (nvh >= H) continue;
          if (nvw >= W) continue;
          if (dist[nvh][nvw] != -1) continue;
          if (grid[nvh][nvw] == '#') continue;
          dist[nvh][nvw] = dist[vh][vw] + 1;
          que.push({nvh, nvw});
        }
        for (int gh = 0; gh < H; gh++)
          for (int gw = 0; gw < W; gw++) res = max(res, dist[gh][gw]);
      }
    }
  }
  cout << res << endl;
  return 0;
}
