#include <bits/stdc++.h>
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename KeyType, typename ValueType>
std::pair<KeyType, ValueType> get_max(const std::map<KeyType, ValueType>& x) {
  using pairtype = std::pair<KeyType, ValueType>;
  return *std::max_element(x.begin(), x.end(),
                           [](const pairtype& p1, const pairtype& p2) {
                             return p1.second < p2.second;
                           });
}
using namespace std;
using P = pair<int, int>;
using ll = long long;
const ll INF = 1LL << 60;
const int MAXN = 25;
int main() {
  int h, w;
  char graph[MAXN][MAXN];
  cin >> h >> w;
  for (int i = 0; i < (h); ++i) {
    for (int j = 0; j < (w); ++j) {
      cin >> graph[i][j];
    }
  }
  int distance[MAXN][MAXN];
  int dismax;
  bool visited[MAXN][MAXN];
  vector<int> dismaxes;
  queue<P> qi;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (graph[i][j] == '#') continue;
      dismax = 0;
      for (int k = 0; k < MAXN; k++) {
        for (int l = 0; l < MAXN; l++) {
          distance[k][l] = 0;
          visited[k][l] = false;
        }
      }
      qi.push(make_pair(i, j));
      while (!qi.empty()) {
        P v = qi.front();
        qi.pop();
        int x = v.second;
        int y = v.first;
        int dx[] = {0, 0, 1, -1};
        int dy[] = {1, -1, 0, 0};
        visited[y][x] = true;
        for (int i = 0; i < 4; i++) {
          int x2 = x + dx[i];
          int y2 = y + dy[i];
          if (0 <= x2 && 0 <= y2 && w > x2 && h > y2 && !visited[y2][x2] &&
              graph[y2][x2] != '#') {
            qi.push(make_pair(y2, x2));
            distance[y2][x2] = distance[y][x] + 1;
            dismax = max(dismax, distance[y2][x2]);
          }
        }
      }
      dismaxes.push_back(dismax);
    }
  }
  cout << *max_element(dismaxes.begin(), dismaxes.end()) << endl;
  return 0;
}
