#include <bits/stdc++.h>
using namespace std;
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 i = 0; i < h; i++) cin >> grid[i];
  int res = -1;
  for (int sh = 0; sh < h; sh++) {
    for (int sw = 0; sw < w; sw++) {
      for (int gh = 0; gh < h; gh++) {
        for (int gw = 0; gw < w; gw++) {
          if (grid[sh][sw] == '#') continue;
          if (grid[gh][gw] == '#') continue;
          if (sh == gh && sw == gw) continue;
          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 i = 0; i < 4; i++) {
              int nvh = vh + dx[i];
              int nvw = vw + dy[i];
              if (nvh < 0) continue;
              if (nvw < 0) continue;
              if (nvh >= h) continue;
              if (nvh >= w) continue;
              if (dist[nvh][nvw] != -1) continue;
              if (grid[nvh][nvw] == '#') continue;
              dist[nvh][nvw] = dist[vh][vw] + 1;
              que.push({nvh, nvw});
            }
          }
          if (dist[gh][gw] != -1) res = max(res, dist[gh][gw]);
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}
