#include <bits/stdc++.h>
using namespace std;
int H, W;
string S[25];
int dis[25][25];
int INF = 9999;
void SHOKI(void) {
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      dis[i][j] = INF;
    }
  }
}
queue<pair<int, int> > q;
void BFS(int i, int j) {
  q.push(make_pair(i, j));
  while (q.size() > 0) {
    pair<int, int> p;
    p = q.front();
    int u = p.first;
    int v = p.second;
    q.pop();
    if (S[u - 1][v] == '.' && dis[u - 1][v] == INF) {
      dis[u - 1][v] = dis[u][v] + 1;
      q.push(make_pair(u - 1, v));
    }
    if (S[u + 1][v] == '.' && dis[u + 1][v] == INF) {
      dis[u + 1][v] = dis[u][v] + 1;
      q.push(make_pair(u + 1, v));
    }
    if (S[u][v - 1] == '.' && dis[u][v - 1] == INF) {
      dis[u][v - 1] = dis[u][v] + 1;
      q.push(make_pair(u, v - 1));
    }
    if (S[u][v + 1] == '.' && dis[u][v + 1] == INF) {
      dis[u][v + 1] = dis[u][v] + 1;
      q.push(make_pair(u, v + 1));
    }
  }
}
int CALC(void) {
  int ret = 0;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (dis[i][j] == INF) {
        continue;
      }
      ret = max(ret, dis[i][j]);
    }
  }
  return ret;
}
int main(void) {
  cin >> H >> W;
  for (int i = 1; i <= H; i++) {
    cin >> S[i];
  }
  for (int i = 0; i <= W; i++) {
    S[0] += "#";
    S[H + 1] += "#";
  }
  for (int i = 1; i <= H; i++) {
    S[i] = "#" + S[i] + "#";
  }
  int ans = 0;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      SHOKI();
      dis[i][j] = 0;
      BFS(i, j);
      ans = max(ans, CALC());
    }
  }
  cout << ans << endl;
  return 0;
}
