#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr int INF = 1 << 30;
ll h, w;
string a[22];
int dx[4] = {0, -1, 1, 0};
int dy[4] = {1, 0, 0, -1};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> h >> w;
  for (int i = 0; i < (h); ++i) cin >> a[i];
  int ans = 0;
  for (int i = 0; i < h; ++i)
    for (int j = 0; j < w; ++j)
      for (int k = 0; k < h; ++k)
        for (int l = 0; l < w; ++l) {
          vector<vector<int>> dist(h, vector<int>(w, INF));
          queue<pair<int, int>> q;
          dist[i][j] = 0;
          q.emplace(i, j);
          while (q.size()) {
            int y = q.front().first;
            int x = q.front().second;
            q.pop();
            for (int d = 0; d < 4; ++d) {
              int ny = y + dy[d];
              int nx = x + dx[d];
              if (0 <= ny && ny < h && 0 <= nx && nx < w && a[ny][nx] == '.') {
                if (dist[ny][nx] > dist[y][x] + 1) {
                  dist[ny][nx] = dist[y][x] + 1;
                  q.emplace(ny, nx);
                }
              }
            }
          }
          if (dist[k][l] != INF) ans = max(ans, dist[k][l]);
        }
  cout << ans;
  return 0;
}
