#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int H, W, dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
  cin >> H >> W;
  vector<string> vv(H);
  for (long long int i = 0; i < (H); i++) cin >> vv[i];
  vector<string> v(H + 2);
  for (long long int i = 0; i < (W + 2); i++) v[0].push_back('#');
  for (long long int i = 0; i < (H); i++) {
    v[i + 1].push_back('#');
    for (long long int j = 0; j < (W); j++) v[i + 1].push_back(vv[i][j]);
    v[i + 1].push_back('#');
  }
  for (long long int i = 0; i < (W + 2); i++) v[H + 1].push_back('#');
  H += 2;
  W += 2;
  vector<vector<long long int>> w(H, vector<long long int>(W, -1));
  long long int ans = 0;
  for (long long int sx = 0; sx < (W); sx++) {
    for (long long int sy = 0; sy < (H); sy++) {
      for (long long int gx = 0; gx < (W); gx++) {
        for (long long int gy = 0; gy < (H); gy++) {
          if (v[gy][gx] == '#' || v[sy][sx] == '#') continue;
          for (long long int i = 0; i < (H); i++) {
            for (long long int j = 0; j < (W); j++) {
              if (v[i][j] == '#')
                w[i][j] = -2;
              else
                w[i][j] = -1;
            }
          }
          queue<pair<long long int, long long int>> que;
          que.push(pair<long long int, long long int>(sy, sx));
          while (!que.empty()) {
            auto c = que.front();
            que.pop();
            for (long long int i = 0; i < (4); i++) {
              long long int ny = c.first + dy[i];
              long long int nx = c.second + dx[i];
              if (w[ny][nx] == -2 || nx < 0 || ny < 0 || nx >= W || ny >= H)
                continue;
              if (w[ny][nx] == -1) {
                w[ny][nx] = w[c.first][c.second] + 1;
                que.push(pair<long long int, long long int>(ny, nx));
              }
            }
          }
          ans = max(w[gy][gx] + 1, ans);
        }
      }
    }
  }
  cout << ans << endl;
}
