#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod = 1e9 + 7;
int nlx[4] = {0, 0, 1, -1};
int nly[4] = {1, -1, 0, 0};
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i(0); i < H; i++) cin >> S[i];
  vector<int> ans;
  for (int sx(0); sx < W; sx++) {
    for (int sy(0); sy < H; sy++) {
      for (int gx(0); gx < W; gx++) {
        for (int gy(0); gy < H; gy++) {
          if (S[sy][sx] == '#' || S[gy][gx] == '#') continue;
          vector<string> s = S;
          int cnt[20][20] = {0};
          s[sy][sx] = 's';
          s[gy][gx] = 'g';
          queue<pair<int, int>> q;
          q.push({sx, sy});
          bool flag = true;
          while (!q.empty() && flag) {
            pair<int, int> now = q.front();
            q.pop();
            if (s[now.second][now.first] == '#') continue;
            s[now.second][now.first] = '#';
            for (int i(0); i < 4; i++) {
              pair<int, int> next = {now.first + nlx[i], now.second + nly[i]};
              if (next.first < 0 || next.first >= W || next.second < 0 ||
                  next.second >= H)
                continue;
              cnt[next.second][next.first] = cnt[now.second][now.first] + 1;
              if (next.first == gx && next.second == gy) {
                ans.push_back(cnt[next.second][next.first]);
                flag = false;
              }
              q.push(next);
            }
          }
        }
      }
    }
  }
  int ansi(0);
  for (int i(0); i < ans.size(); i++) {
    ansi = max(ans[i], ansi);
  }
  cout << ansi << endl;
  return 0;
}
