#include <bits/stdc++.h>
using namespace std;
template <class A>
void pr(A a) {
  cout << (a) << endl;
}
template <class A, class B>
void pr(A a, B b) {
  cout << a << " ";
  pr(b);
}
template <class A, class B, class C>
void pr(A a, B b, C c) {
  cout << a << " ";
  pr(b, c);
}
template <class A, class B, class C, class D>
void pr(A a, B b, C c, D d) {
  cout << a << " ";
  pr(b, c, d);
}
int INF = numeric_limits<int>::max();
int main(void) {
  int H, W;
  cin >> H >> W;
  char S[H + 10][W + 10];
  for (int i = int(0); i <= int(H - 1); ++i) {
    for (int j = int(0); j <= int(W - 1); ++j) {
      cin >> S[i][j];
    }
  }
  vector<pair<int, int> > XY;
  XY.push_back(make_pair(1, 0));
  XY.push_back(make_pair(0, 1));
  XY.push_back(make_pair(-1, 0));
  XY.push_back(make_pair(0, -1));
  int ans = 0;
  for (int i = int(0); i <= int(H - 1); ++i) {
    for (int j = int(0); j <= int(W - 1); ++j) {
      int seen[H + 10][W + 10];
      fill(seen[0], seen[H + 10], 0);
      int dist[H + 10][W + 10];
      fill(dist[0], dist[H + 10], INF);
      queue<pair<int, int> > todo;
      todo.push(make_pair(i, j));
      dist[i][j] = 0;
      while (!todo.empty()) {
        pair<int, int> tar = todo.front();
        todo.pop();
        if (!seen[tar.first][tar.second]) {
          for (auto xy : XY) {
            if ((0 <= tar.first + xy.first && 0 <= tar.second + xy.second) &&
                (tar.first + xy.first < H && tar.second + xy.second < W) &&
                (S[tar.first + xy.first][tar.second + xy.second] == '.')) {
              todo.push(
                  make_pair(tar.first + xy.first, tar.second + xy.second));
              if (dist[tar.first + xy.first][tar.second + xy.second] == INF)
                dist[tar.first + xy.first][tar.second + xy.second] =
                    dist[tar.first][tar.second] + 1;
              ans =
                  max(dist[tar.first + xy.first][tar.second + xy.second], ans);
            }
          }
          seen[tar.first][tar.second] = 1;
        }
      }
    }
  }
  pr(ans);
  return 0;
}
