#include <bits/stdc++.h>
using namespace std;
template <typename A, size_t N, typename T>
void static_fill(A (&arr)[N], const T &val) {
  fill((T *)arr, (T *)(arr + N), val);
}
const int dy[4] = {1, -1, 0, 0};
const int dx[4] = {0, 0, 1, -1};
int H, W;
char bd[22][22];
int d[22][22][22][22];
void wf() {
  static_fill(d, 10000);
  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      if (bd[i][j] == '#') continue;
      d[i][j][i][j] = 0;
      for (int k = 0; k < 4; ++k) {
        if (bd[i + dy[k]][j + dx[k]] == '#') continue;
        d[i][j][i + dy[k]][j + dx[k]] = 1;
        d[i + dy[k]][j + dx[k]][i][j] = 1;
      }
    }
  }
  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      if (bd[i][j] == '#') continue;
      for (int k = 1; k <= H; ++k) {
        for (int l = 1; l <= W; ++l) {
          if (bd[k][l] == '#') continue;
          for (int m = 1; m <= H; ++m) {
            for (int n = 1; n <= W; ++n) {
              if (bd[m][n] == '#') continue;
              d[k][l][m][n] = min(d[k][l][m][n], d[k][l][i][j] + d[i][j][m][n]);
            }
          }
        }
      }
    }
  }
}
int main() {
  static_fill(bd, '#');
  cin >> H >> W;
  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      cin >> bd[i][j];
    }
  }
  wf();
  int mx = 0;
  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) {
          mx = max(mx, d[i][j][k][l]);
        }
      }
    }
  }
  cout << mx << endl;
  return 0;
}
