#include <bits/stdc++.h>
using namespace std;
const int N = 25;
int t[N][N], d[N][N][N][N];
int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};
int n, m;
bool ok(int x, int y) {
  return 0 <= x and x < n and 0 <= y and y < m and t[x][y];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      for (int k = 0; k < n; ++k) {
        for (int g = 0; g < m; ++g) {
          d[i][j][k][g] = 228;
        }
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      char c;
      cin >> c;
      t[i][j] = (c == '.');
      d[i][j][i][j] = 0;
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      for (int k = 0; k < 4; ++k) {
        if (ok(i + dx[k], j + dy[k])) {
          d[i][j][i + dx[k]][j + dy[k]] = 1;
        }
      }
    }
  }
  for (int kx = 0; kx < n; ++kx) {
    for (int ky = 0; ky < m; ++ky) {
      for (int ix = 0; ix < n; ++ix) {
        for (int iy = 0; iy < m; ++iy) {
          for (int jx = 0; jx < n; ++jx) {
            for (int jy = 0; jy < m; ++jy) {
              d[ix][iy][jx][jy] =
                  min(d[ix][iy][jx][jy], d[ix][iy][kx][ky] + d[kx][ky][jx][jy]);
            }
          }
        }
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      for (int k = 0; k < n; ++k) {
        for (int g = 0; g < m; ++g) {
          if (t[i][j] and t[k][g]) {
            ans = max(ans, d[i][j][k][g]);
          }
        }
      }
    }
  }
  cout << ans;
  return 0;
}
