#include <bits/stdc++.h>
using namespace std;
const int INT_INF = 2147483647;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 100000000;
char a[50][50];
int H, W;
int d[50][50];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int bfs(int x, int y) {
  queue<pair<int, int> > que;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      d[i][j] = INF;
    }
  }
  que.push(pair<int, int>(x, y));
  d[x][y] = 0;
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx && nx < H && 0 <= ny && ny < W && a[nx][ny] != '#' &&
          d[nx][ny] == INF) {
        que.push(pair<int, int>(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < (H); ++i)
    for (int j = 0; j < (W); ++j) {
      if (d[i][j] != INF) chmax(ans, d[i][j]);
      d[i][j] = INF;
    }
  return ans;
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> a[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < (H); ++i)
    for (int j = 0; j < (W); ++j) {
      chmax(ans, bfs(i, j));
    }
  cout << ans << endl;
  return 0;
}
