#include <bits/stdc++.h>
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
char G[22][22];
queue<pair<int, int>> que;
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, -1, 0, 1};
int main() {
  int h, w;
  cin >> h >> w;
  int ans = 0;
  for (long long i = 0; i < (h); ++i) {
    for (long long j = 0; j < (w); ++j) {
      cin >> G[i][j];
    }
  }
  for (long long i = 0; i < (h); ++i) {
    for (long long j = 0; j < (w); ++j) {
      que.push(pair<int, int>(i, j));
      int dist[22][22];
      for (long long k = 0; k < (h); ++k) {
        for (long long l = 0; l < (w); ++l) {
          dist[k][l] = -1;
        }
      }
      dist[i][j] = 0;
      while (!que.empty()) {
        pair<int, int> p = que.front();
        que.pop();
        for (long long i = 0; i < (4); ++i) {
          int ny = p.first + dy[i];
          int nx = p.second + dx[i];
          if (-1 < ny && ny < h && -1 < nx && nx < w && G[ny][nx] == '.' &&
              dist[ny][nx] == -1) {
            dist[ny][nx] = dist[p.first][p.second] + 1;
            que.push(pair<int, int>(ny, nx));
          }
        }
      }
      for (long long k = 0; k < (h); ++k) {
        for (long long l = 0; l < (w); ++l) {
          ans = max(ans, dist[k][l]);
        }
      }
    }
  }
  cout << (ans) << endl;
}
