#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
inline bool equals(long double a, long double b) { return fabs(a - b) < 1e-9; }
void solve() {
  long long h, w;
  cin >> h >> w;
  char arr[h][w];
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      cin >> arr[i][j];
    }
  }
  long long d[h][w][h][w];
  memset(d, 1000000007, sizeof(d));
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      d[i][j][i][j] = 0;
      if (j + 1 < w && arr[i][j + 1] != '#') d[i][j][i][j + 1] = 1;
      if (i + 1 < h && arr[i + 1][j] != '#') d[i][j][i + 1][j] = 1;
      if (j - 1 >= 0 && arr[i][j - 1] != '#') d[i][j][i][j - 1] = 1;
      if (i - 1 >= 0 && arr[i - 1][j] != '#') d[i][j][i - 1][j] = 1;
    }
  }
  long long ans = 0;
  for (long long kh = 0; kh < h; kh++) {
    for (long long kw = 0; kw < w; kw++) {
      for (long long ih = 0; ih < h; ih++) {
        for (long long iw = 0; iw < w; iw++) {
          for (long long jh = 0; jh < h; jh++) {
            for (long long jw = 0; jw < w; jw++) {
              d[ih][iw][jh][jw] =
                  min(d[ih][iw][jh][jw], d[ih][iw][kh][kw] + d[kh][kw][jh][jw]);
            }
          }
        }
      }
    }
  }
  for (long long ih = 0; ih < h; ih++) {
    for (long long iw = 0; iw < w; iw++) {
      for (long long jh = 0; jh < h; jh++) {
        for (long long jw = 0; jw < w; jw++) {
          if (d[ih][iw][jh][jw] < 1000000007) ans = max(ans, d[ih][iw][jh][jw]);
        }
      }
    }
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  };
  return 0;
}
