#include <bits/stdc++.h>
using namespace std;
using Edge = pair<long long, long long>;
using Graph = vector<vector<int>>;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
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;
}
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
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; }
int main() {
  long long H, W, ans = 0;
  cin >> H >> W;
  char S[H][W];
  for (int i = (0); i < (H); ++i) {
    for (int j = (0); j < (W); ++j) {
      cin >> S[i][j];
    }
  }
  for (int i = (0); i < (H); ++i) {
    for (int j = (0); j < (W); ++j) {
      if (S[i][j] == '#') continue;
      long long DIS[H][W];
      bool CAN[H][W];
      for (int k = (0); k < (H); ++k) {
        for (int l = (0); l < (W); ++l) {
          DIS[k][l] = 5100000;
          CAN[k][l] = false;
        }
      }
      DIS[i][j] = 0;
      queue<pair<long long, long long>> Q;
      Q.push(make_pair(i, j));
      while (!Q.empty()) {
        auto it = Q.front();
        Q.pop();
        long long vx = it.first, vy = it.second;
        CAN[vx][vy] = true;
        for (int k = (0); k < (4); ++k) {
          long long nx = vx + dx[k], ny = vy + dy[k];
          if (nx < 0 || H <= nx || ny < 0 || W <= ny) continue;
          if (S[nx][ny] == '#' || CAN[nx][ny]) continue;
          chmin(DIS[nx][ny], DIS[vx][vy] + 1);
          Q.push(make_pair(nx, ny));
        }
      }
      for (int k = (0); k < (H); ++k) {
        for (int l = (0); l < (W); ++l) {
          if (DIS[k][l] != 5100000) chmax(ans, DIS[k][l]);
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}
