#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
  long long result{0};
  long long h, w;
  cin >> h >> w;
  int a[22][22];
  vector<vector<vector<pair<int, int>>>> b(22,
                                           vector<vector<pair<int, int>>>(22));
  memset(a, -1, sizeof(a));
  for (long long i = 0; i < long long(h); i++)
    for (long long j = 0; j < long long(w); j++) {
      char ch;
      cin >> ch;
      if (ch == '.')
        a[i][j] = 0;
      else
        a[i][j] = 1;
    }
  int dx[4] = {-1, 0, 1, 0};
  int dy[4] = {0, -1, 0, 1};
  for (long long x = 0; x < long long(h); x++)
    for (long long y = 0; y < long long(w); y++) {
      for (long long i = 0; i < long long(4); i++) {
        if (a[x + dx[i]][y + dy[i]] == 0) {
          b[x][y].push_back(make_pair(x + dx[i], y + dy[i]));
        }
      }
    }
  for (long long x = 0; x < long long(h); x++)
    for (long long y = 0; y < long long(w); y++) {
      int c[22][22] = {};
      int depth[22][22] = {};
      queue<pair<int, int>> que;
      que.push(make_pair(x, y));
      while (!que.empty()) {
        pair<int, int> u = que.front();
        que.pop();
        for (long long i = 0; i < long long(b[u.first][u.second].size()); i++) {
          if (c[b[u.first][u.second][i].first]
               [b[u.first][u.second][i].second] == 0) {
            c[b[u.first][u.second][i].first][b[u.first][u.second][i].second] =
                1;
            depth[b[u.first][u.second][i].first]
                 [b[u.first][u.second][i].second] =
                     depth[u.first][u.second] + 1;
            result = max((int)result, depth[u.first][u.second] + 1);
            que.push(make_pair(b[u.first][u.second][i].first,
                               b[u.first][u.second][i].second));
          }
        }
      }
    }
  cout << result << endl;
  return 0;
}
