#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; };
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; };
long long mod(long long a, long long b) { return (a + b - 1) / b; };
long long month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
  std::fill((T*)array, (T*)(array + N), val);
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
};
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
};
long long N, M;
long long h, w;
string maze[100];
long long a[100][100];
long long dx[4] = {1, 0, -1, 0}, dy[4] = {0, -1, 0, 1};
long long bfs(long long sx, long long sy, long long gx, long long gy) {
  Fill(a, LLONG_MAX - 100);
  queue<pair<long long, long long> > que;
  que.push(pair<long long, long long>(sx, sy));
  a[sy][sx] = 0;
  while (que.size()) {
    pair<long long, long long> p = que.front();
    que.pop();
    for (long long(i) = 0; i < (4); i++) {
      long long nx = p.first + dx[i];
      long long ny = p.second + dy[i];
      if (0 <= nx && nx < w && 0 <= ny && ny < h) {
        if (a[ny][nx] == LLONG_MAX - 100 && maze[ny][nx] != '#') {
          a[ny][nx] = a[p.second][p.first] + 1;
          que.push(pair<long long, long long>(nx, ny));
        }
      }
    }
  }
  return a[gy][gx];
}
signed main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> w;
  for (long long(i) = 0; i < (h); i++) cin >> maze[i];
  long long ans = 0;
  for (long long(i1) = 0; i1 < (h); i1++) {
    for (long long(j1) = 0; j1 < (w); j1++) {
      for (long long(i2) = 0; i2 < (h); i2++) {
        for (long long(j2) = 0; j2 < (w); j2++) {
          long long now = bfs(j1, i1, j2, i2);
          if (now != LLONG_MAX - 100) chmax(ans, now);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
