#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
void sort_second(vector<pair<long long, long long>> &A, int N);
long long a_n(long long a, long long n);
int main() {
  int h, w;
  int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
  cin >> h >> w;
  int maze[h][w];
  for (int(i) = 0; (i) < (int)(h); (i)++)
    for (int(j) = 0; (j) < (int)(w); (j)++) maze[i][j] = 1;
  for (int(i) = 0; (i) < (int)(h); (i)++) {
    string s;
    cin >> s;
    for (int(j) = 0; (j) < (int)(w); (j)++) {
      if (s[j] == '.') maze[i][j] = 0;
    }
  }
  int max = 0, sx, sy, dist[h][w];
  for (int(i) = 0; (i) < (int)(h); (i)++) {
    for (int(j) = 0; (j) < (int)(w); (j)++) {
      sx = i, sy = j;
      for (int(k) = 0; (k) < (int)(h); (k)++)
        for (int(l) = 0; (l) < (int)(w); (l)++) dist[k][l] = INF * (-1);
      queue<pair<int, int>> que;
      que.push(pair<int, int>(sx, sy));
      dist[sx][sy] = 0;
      while (que.size()) {
        pair<int, int> p = que.front();
        que.pop();
        for (int(k) = 0; (k) < (int)(4); (k)++) {
          int nx = p.first + dx[k], ny = p.second + dy[k];
          if (0 <= nx && nx < h && 0 <= ny && ny < w && maze[nx][ny] != 1 &&
              dist[nx][ny] == (INF * (-1))) {
            que.push(pair<int, int>(nx, ny));
            dist[nx][ny] = dist[p.first][p.second] + 1;
          }
        }
      }
      for (int(k) = 0; (k) < (int)(h); (k)++) {
        for (int(l) = 0; (l) < (int)(w); (l)++) {
          if (max <= dist[k][l]) max = dist[k][l];
        }
      }
    }
  }
  cout << max << endl;
  return 0;
}
void sort_second(vector<pair<long long, long long>> &A, int N) {
  for (int(i) = 0; (i) < (int)(N); (i)++) swap(A.at(i).first, A.at(i).second);
  sort((A).begin(), (A).end());
  for (int(i) = 0; (i) < (int)(N); (i)++) swap(A.at(i).first, A.at(i).second);
}
long long a_n(long long a, long long n) {
  long long ret = a, count = 1;
  while (count * 2 < n) {
    ret *= ret;
    count *= 2;
  }
  if (count == n)
    return ret;
  else
    return ret * a_n(a, n - count);
}
