#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int R, C;
char c[21][21];
int ans[21][21];
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
int main() {
  cin >> R >> C;
  for (int i = 0; i < R; ++i) {
    for (int j = 0; j < C; ++j) {
      cin >> c[i][j];
    }
  }
  int tmp = -1;
  for (int sx = 0; sx < (C); sx++) {
    int ans[20][20];
    queue<pair<int, int> > q;
    memset(ans, 0, sizeof(ans));
    for (int sy = 0; sy < (R); sy++) {
      for (int gx = 0; gx < (C); gx++) {
        for (int gy = 0; gy < (R); gy++) {
          q.push(make_pair(sy, sx));
          ans[sy][sx] = 0;
          while (!q.empty()) {
            pair<int, int> pos = q.front();
            q.pop();
            for (int i = 0; i < 4; ++i) {
              int nowy = pos.first + dy[i], nowx = pos.second + dx[i];
              if (ans[nowy][nowx] != 0) continue;
              if (0 <= nowx && nowx < C && 0 <= nowy && nowy < R) {
                if (c[nowy][nowx] == '.') {
                  ans[nowy][nowx] = ans[pos.first][pos.second] + 1;
                  q.push(make_pair(nowy, nowx));
                }
              }
            }
          }
          chmax(tmp, ans[gy][gx]);
        }
      }
    }
  }
  cout << tmp << endl;
}
