#include <bits/stdc++.h>
using namespace std;
long long int powmod(long long int a, long long int b) {
  long long int res = 1;
  a %= 1005;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % 1005;
    a = a * a % 1005;
  }
  return res;
}
int nxt() {
  int x;
  scanf("%d", &x);
  return x;
}
int main() {
  int row = nxt(), col = nxt();
  int b = 0;
  int grid[row][col];
  for (int i = 0; i < row; i++)
    for (int j = 0; j < col; j++) {
      char ch;
      cin >> ch;
      if (ch == '.')
        grid[i][j] = 1;
      else
        grid[i][j] = 0;
    }
  int dist[row][col];
  for (int i = 0; i < row; i++)
    for (int j = 0; j < col; j++) {
      for (int k = 0; k < row; k++)
        for (int l = 0; l < col; l++) dist[k][l] = 1000000007;
      dist[i][j] = 0;
      queue<pair<int, pair<int, int>>> q;
      q.push({0, {i, j}});
      while (!q.empty()) {
        auto front = q.front();
        q.pop();
        int d = front.first, x = front.second.first, y = front.second.second;
        if (d > dist[x][y]) continue;
        dist[x][y] = d;
        int rN[4] = {0, 0, 1, -1};
        int cN[4] = {1, -1, 0, 0};
        for (int a = 0; a < 4; a++) {
          int nX = cN[a] + x;
          int nY = rN[a] + y;
          if (nX < 0 || nX >= row || nY < 0 || nY >= col || grid[nX][nY] == 0)
            continue;
          if (dist[nX][nY] > dist[x][y] + 1) {
            dist[nX][nY] = dist[x][y] + 1;
            q.push({dist[nX][nY], {nX, nY}});
          }
        }
      }
      for (int k = 0; k < row; k++)
        for (int l = 0; l < col; l++) {
          if (dist[k][l] != 1000000007) b = max(b, dist[k][l]);
        }
    }
  printf("%d\n", b);
  return 0;
}
