#include <bits/stdc++.h>
using namespace std;
constexpr int inf = 1e9 + 7, mv[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};
int main() {
  int h, w, s[22][22], pos[22][22][22][22], mx = 0;
  scanf("%d%d", &h, &w);
  for (int i = 1; i <= h; ++i) {
    scanf("\n");
    for (int j = 1; j <= w; ++j) {
      char k;
      scanf("%c", &k);
      s[i][j] = k == '.';
    }
  }
  for (int i = 0; i <= h + 1; ++i) {
    for (int j = 0; j <= w + 1; ++j) {
      for (int k = 0; k <= h + 1; ++k) {
        for (int l = 0; l <= w + 1; ++l) {
          pos[i][j][k][l] = inf;
        }
      }
    }
  }
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      pos[i][j][i][j] = 0;
      for (int k = 0; k < 4; ++k) {
        if (s[i + mv[k][0]][j + mv[k][1]]) {
          pos[i][j][i + mv[k][0]][j + mv[k][1]] = 1;
        }
      }
    }
  }
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      for (int k = 1; k <= h; ++k) {
        for (int l = 1; l <= w; ++l) {
          for (int m = 1; m <= h; ++m) {
            for (int n = 1; n <= w; ++n) {
              pos[k][l][m][n] =
                  min(pos[k][l][m][n], pos[k][l][i][j] + pos[i][j][m][n]);
            }
          }
        }
      }
    }
  }
  for (int i = 1; i <= h; ++i) {
    for (int j = 1; j <= w; ++j) {
      for (int k = 1; k <= h; ++k) {
        for (int l = 1; l <= w; ++l) {
          if (pos[i][j][k][l] < inf) {
            mx = max(mx, pos[i][j][k][l]);
          }
        }
      }
    }
  }
  printf("%d\n", mx);
}
