#include <bits/stdc++.h>
using namespace std;
long long INF = 1e14 + 7;
long long MOD = 998244353;
int main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long h, w;
  ;
  cin >> h;
  ;
  ;
  cin >> w;
  ;
  char arr[h][w];
  long long s1 = -1, s2 = 1;
  long long dist[20][20][20][20];
  for (long long i = 0; i < 20; i++) {
    for (long long j = 0; j < 20; j++) {
      for (long long ki = 0; ki < 20; ki++) {
        for (long long kj = 0; kj < 20; kj++) {
          dist[i][j][i][j] = 0;
          dist[i][j][ki][kj] = INF;
        }
      }
    }
  }
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      ;
      cin >> arr[i][j];
      ;
      if (arr[i][j] == '.') {
        if (j + 1 < 20) dist[i][j][i][j + 1] = 1;
        if (j > 0) dist[i][j][i][j - 1] = 1;
        if (i > 0) dist[i][j][i - 1][j] = 1;
        if (i + 1 < 20) dist[i][j][i + 1][j] = 1;
      } else {
        for (long long ki = 0; ki < 20; ki++) {
          for (long long kj = 0; kj < 20; kj++) {
            dist[i][j][ki][kj] = INF;
          }
        }
      }
    }
  }
  for (long long ki = 0; ki < h; ki++) {
    for (long long kj = 0; kj < w; kj++) {
      for (long long i = 0; i < h; i++) {
        for (long long j = 0; j < w; j++) {
          for (long long pair<long long, long long> = 0;
               pair<long long, long long> < h; pair<long long, long long> ++) {
            for (long long jj = 0; jj < w; jj++) {
              dist[i][j][pair<long long, long long>][jj] =
                  min(dist[i][j][pair<long long, long long>][jj],
                      dist[i][j][ki][kj] +
                          dist[ki][kj][pair<long long, long long>][jj]);
            }
          }
        }
      }
    }
  }
  long long ans = -INF;
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      for (long long ki = 0; ki < h; ki++) {
        for (long long kj = 0; kj < w; kj++) {
          if (dist[i][j][ki][kj] < INF) ans = max(ans, dist[i][j][ki][kj]);
        }
      }
    }
  }
  cout << max(ans, 0LL) << endl;
  ;
}
