#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int V;
using namespace std;
static const int N = 100;
static const int INFTY = (1 << 21);
static const int white = 0;
static const int gray = 1;
static const int black = 2;
int H, W;
int ans = 0;
int sy, sx, gy, gx;
int M[N][N];
int d[N][N];
int color[N][N];
vector<string> S;
void bfs(int sy, int sx) {
  queue<pair<int, int> > Q;
  color[sy][sx] = gray;
  d[sy][sx] = 0;
  Q.push(make_pair(sy, sx));
  while (!Q.empty()) {
    pair<int, int> u = Q.front();
    Q.pop();
    color[u.first][u.second] = black;
    if (u.first + 1 < H) {
      if (color[u.first + 1][u.second] == white) {
        Q.push(make_pair(u.first + 1, u.second));
        color[u.first + 1][u.second] = gray;
        d[u.first + 1][u.second] = d[u.first][u.second] + 1;
      }
    }
    if (u.first - 1 >= 0) {
      if (color[u.first - 1][u.second] == white) {
        Q.push(make_pair(u.first - 1, u.second));
        color[u.first - 1][u.second] = gray;
        d[u.first - 1][u.second] = d[u.first][u.second] + 1;
      }
    }
    if (u.second + 1 < W) {
      if (color[u.first][u.second + 1] == white) {
        Q.push(make_pair(u.first, u.second + 1));
        color[u.first][u.second + 1] = gray;
        d[u.first][u.second + 1] = d[u.first][u.second] + 1;
      }
    }
    if (u.second - 1 >= 0) {
      if (color[u.first][u.second - 1] == white) {
        Q.push(make_pair(u.first, u.second - 1));
        color[u.first][u.second - 1] = gray;
        d[u.first][u.second - 1] = d[u.first][u.second] + 1;
      }
    }
  }
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++)
      if (d[i][j] != INF) ans = max(ans, d[i][j]);
}
int main() {
  cin >> H >> W;
  S.resize(H);
  for (int i = 0; i < H; i++) cin >> S[i];
  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++) {
          d[k][l] = INF;
          if (S[k][l] == '.')
            color[k][l] = white;
          else
            color[k][l] = black;
        }
      bfs(i, j);
    }
  cout << ans << endl;
}
