#include <bits/stdc++.h>
const long long LLINF = 1LL << 60;
const int INF = 1e9;
const long long MOD = 1000000007;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
struct P {
  int x;
  int y;
};
int dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, -1, 1};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int h, w;
  cin >> h >> w;
  vector<string> field(h);
  for (int i = 0; i < h; i++) cin >> field[i];
  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (i == j) continue;
      if (field[i][j] == '#') continue;
      for (int i2 = 0; i2 < h; i2++) {
        for (int j2 = 0; j2 < w; j2++) {
          if (i2 == j2) continue;
          if (i <= i2 && j <= j2) continue;
          if (field[i2][j2] == '#') continue;
          int point[51][51];
          for (int k = 0; k < h; k++) {
            for (int l = 0; l < w; l++) {
              point[k][l] = INF;
            }
          }
          queue<P> que;
          point[i][j] = 0;
          que.push({j, i});
          while (que.size()) {
            P nowp = que.front();
            que.pop();
            int now_x = nowp.x, now_y = nowp.y;
            if (now_x == j2 && now_y == i2)
              break;
            else {
              for (int k = 0; k < 4; k++) {
                int next_x = now_x + dx[k], next_y = now_y + dy[k];
                if (next_x >= 0 && next_x < w && next_y >= 0 && next_y < h &&
                    field[next_y][next_x] != '#' &&
                    point[next_y][next_x] == INF) {
                  que.push({next_x, next_y});
                  point[next_y][next_x] = point[now_y][now_x] + 1;
                }
              }
            }
          }
          ans = max(ans, point[i2][j2]);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
