#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  string S[22];
  for (int i = 0; i < H; i++) {
    cin >> S[i + 1];
    S[i + 1] = "#" + S[i + 1] + "#";
  }
  S[0] = "";
  S[H] = "";
  for (int i = 0; i < W + 10; i++) {
    S[0] += "#";
    S[H + 1] += "#";
  }
  int ans = 0;
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (S[i][j] == '.') {
        int a[30][30];
        for (int k = 0; k < 30; k++) {
          for (int l = 0; l < 30; l++) {
            a[k][l] = -1;
          }
        }
        a[i][j] = 0;
        int c = 0;
        stack<int> sx, sy;
        sx.push(j);
        sy.push(i);
        while (!sx.empty()) {
          int nx = sx.top();
          int ny = sy.top();
          sx.pop();
          sy.pop();
          int dx[4] = {0, 0, 1, -1};
          int dy[4] = {1, -1, 0, 0};
          for (int k = 0; k < 4; k++) {
            int tx = nx + dx[k];
            int ty = ny + dy[k];
            if (S[ty][tx] == '.') {
              if (a[ty][tx] == -1 || a[ny][nx] + 1 < a[ty][tx]) {
                c = max(c, a[ny][nx] + 1);
                a[ty][tx] = a[ny][nx] + 1;
                sx.push(tx);
                sy.push(ty);
              }
            }
          }
        }
        ans = max(ans, c);
      }
    }
  }
  cout << ans << endl;
}
