#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MOD2 = 998244353;
const long long MOD3 = 1812447359;
const long long INF = 1ll << 62;
const double PI = 2 * asin(1);
void yes() { printf("yes\n"); }
void no() { printf("no\n"); }
void Yes() { printf("Yes\n"); }
void No() { printf("No\n"); }
void YES() { printf("YES\n"); }
void NO() { printf("NO\n"); }
int H, W, ans;
int di[4] = {0, -1, 0, 1}, dj[4] = {1, 0, -1, 0};
char S[25][25];
int Dist[25][25];
int Solve(int I, int J) {
  fill((int*)Dist, (int*)(Dist + H), -1);
  queue<pair<int, int> > que;
  que.push({I, J});
  Dist[I][J] = 0;
  while (!que.empty()) {
    pair<int, int> Q = que.front();
    que.pop();
    for (int k = 0; k < 4; k++) {
      int i = Q.first + di[k];
      int j = Q.second + dj[k];
      if (0 <= i && i < H && 0 <= j && j < W) {
        if (Dist[i][j] == -1 && S[i][j] == '.') {
          que.push({i, j});
          Dist[i][j] = Dist[Q.first][Q.second] + 1;
          ans = max(ans, Dist[i][j]);
        }
      }
    }
  }
  return 0;
}
int main() {
  scanf("%d%d", &H, &W);
  for (int i = 0; i < H; i++) scanf("%s", S + i);
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      Solve(i, j);
    }
  }
  printf("%d\n", ans);
  return 0;
}
