#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
ll INF = 1ll << 60;
int move(int sh, int sw, int gh, int gw, vector<string> S, int cnt,
         vector<vector<bool>> visited) {
  visited[sh][sw] = true;
  if (sh == gh && sw == gw) {
    return cnt;
  }
  int ans = 500;
  int H = S.size();
  int W = S[0].size();
  if (sh > 0 && visited[sh - 1][sw] == false) {
    ans = min(ans, move(sh - 1, sw, gh, gw, S, cnt + 1, visited));
  }
  if (sh < H - 1 && visited[sh + 1][sw] == false) {
    ans = min(ans, move(sh + 1, sw, gh, gw, S, cnt + 1, visited));
  }
  if (sw > 0 && visited[sh][sw - 1] == false) {
    ans = min(ans, move(sh, sw - 1, gh, gw, S, cnt + 1, visited));
  }
  if (sw < W - 1 && visited[sh][sw + 1] == false) {
    ans = min(ans, move(sh, sw + 1, gh, gw, S, cnt + 1, visited));
  }
  return ans;
}
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = (int)(0); i < (int)(H); i++) cin >> S[i];
  vector<vector<bool>> wall(H, vector<bool>(W, false));
  for (int i = (int)(0); i < (int)(H); i++) {
    for (int j = (int)(0); j < (int)(W); j++) {
      if (S[i][j] == '#') wall[i][j] = true;
    }
  }
  int ans = 0;
  for (int sh = (int)(0); sh < (int)(H); sh++) {
    for (int sw = (int)(0); sw < (int)(W); sw++) {
      if (S[sh][sw] == '#') continue;
      int cnt1 = 0;
      if (sh == 0 || wall[sh - 1][sw]) cnt1++;
      if (sh == H - 1 || wall[sh + 1][sw]) cnt1++;
      if (sw == 0 || wall[sh][sw - 1]) cnt1++;
      if (sw == W - 1 || wall[sh][sw + 1]) cnt1++;
      if (cnt1 == 1 || cnt1 == 0) continue;
      for (int gh = (int)(0); gh < (int)(H); gh++) {
        for (int gw = (int)(0); gw < (int)(W); gw++) {
          if (S[gh][gw] == '#') continue;
          int cnt2 = 0;
          if (gh == 0 || wall[gh - 1][gw]) cnt2++;
          if (gh == H - 1 || wall[gh + 1][gw]) cnt2++;
          if (gw == 0 || wall[gh][gw - 1]) cnt2++;
          if (gw == W - 1 || wall[gh][gw + 1]) cnt2++;
          if (cnt2 == 1 || cnt2 == 0) continue;
          vector<vector<bool>> visited = wall;
          ans = max(ans, move(sh, sw, gh, gw, S, 0, visited));
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
