#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;
int H, W;
string S[30];
int dist[30][30];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
void init() {
  for (int i = 0; i < 29; i++) {
    for (int j = 0; j < 29; j++) {
      if (dist[i][j] != -1) {
        dist[i][j] = 0;
      }
    }
  }
}
bool dfs(int h, int w) {
  if (dist[h][w] == -1) {
    return false;
  }
  queue<pair<int, int> > que;
  que.push(pair<int, int>(h, w));
  dist[h][w] = 0;
  init();
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i];
      int ny = p.second + dy[i];
      if (dist[nx][ny] == 0) {
        que.push(pair<int, int>(nx, ny));
        dist[nx][ny] = dist[p.first][p.second] + 1;
      }
    }
  }
  return true;
}
int max_dist() {
  int res = 0;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      res = max(res, dist[i][j]);
    }
  }
  return res;
}
int main() {
  cin >> H >> W;
  for (int i = 1; i <= W; i++) {
    dist[0][i] = -1;
    dist[H + 1][i] = -1;
  }
  for (int i = 1; i <= H; i++) {
    dist[i][0] = -1;
    dist[i][W + 1] = -1;
  }
  for (int i = 1; i <= H; i++) {
    cin >> S[i];
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#') {
        dist[i][j + 1] = -1;
      } else {
        dist[i][j + 1] = 0;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      bool res = dfs(i, j);
      if (res == false) {
        continue;
      }
      ans = max(ans, max_dist());
    }
  }
  cout << ans << endl;
}
