#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int INF = 1000000000;
int main() {
  int H, W;
  char a[20][20];
  cin >> H >> W;
  for (int i = 0; i < (int)(H); ++i) {
    for (int j = 0; j < (int)(W); ++j) {
      cin >> a[i][j];
    }
  }
  int dist[20][20][20][20] = {0};
  for (int i = 0; i < (int)(20); ++i) {
    for (int j = 0; j < (int)(20); ++j) {
      for (int k = 0; k < (int)(20); ++k) {
        for (int l = 0; l < (int)(20); ++l) {
          if (i == k && j == l) continue;
          dist[i][j][k][l] = INF;
        }
      }
    }
  }
  for (int i = 0; i < (int)(H); ++i) {
    for (int j = 0; j < (int)(W); ++j) {
      if (a[i][j] == '#') continue;
      int dx[4] = {-1, 1, 0, 0};
      int dy[4] = {0, 0, -1, 1};
      for (int k = 0; k < (int)(4); ++k) {
        int ni = i + dx[k];
        int nj = j + dy[k];
        if (a[ni][nj] == '.') {
          dist[i][j][ni][nj] = 1;
        }
      }
    }
  }
  for (int m = 0; m < (int)(H); ++m) {
    for (int n = 0; n < (int)(W); ++n) {
      for (int i = 0; i < (int)(H); ++i) {
        for (int j = 0; j < (int)(W); ++j) {
          for (int k = 0; k < (int)(H); ++k) {
            for (int l = 0; l < (int)(W); ++l) {
              dist[i][j][k][l] =
                  min(dist[i][j][m][n] + dist[m][n][k][l], dist[i][j][k][l]);
            }
          }
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < (int)(H); ++i) {
    for (int j = 0; j < (int)(W); ++j) {
      for (int k = 0; k < (int)(H); ++k) {
        for (int l = 0; l < (int)(W); ++l) {
          if (a[i][j] == '.' && a[k][l] == '.') {
            ans = max(ans, dist[i][j][k][l]);
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
