#include <bits/stdc++.h>
using namespace std;
int get_int() {
  int x;
  scanf("%d", &x);
  return x;
}
long long get_ll() {
  long long x;
  scanf("%lld", &x);
  return x;
}
double get_db() {
  double x;
  scanf("%lf", &x);
  return x;
}
template <typename T>
int chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  } else
    return 0;
}
template <typename T>
int chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  } else
    return 0;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (int i = (0); i < (v.size()); i++) os << v[i] << " ";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
  for (auto a : v) os << a << " ";
  return os;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& v) {
  os << v.first << " " << v.second << " ";
  return os;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const map<T1, T2>& v) {
  for (auto a : v) cout << a << endl;
  return os;
}
static const int dx[8] = {-1, 0, 1, 0, 1, -1, 1, -1};
static const int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
const double pi = acos(-1.0);
const double eps = 1e-8;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 50;
char G[maxn][maxn];
int d[maxn][maxn];
int ans = 0;
int W, H;
int valid(int x, int y) {
  return (x >= 0 && y >= 0 && x <= W - 1 && y <= H - 1 && G[x][y] == '.');
}
void bfs(int x, int y) {
  d[x][y] = 0;
  queue<pair<int, int> > que;
  que.push(make_pair(x, y));
  while (!que.empty()) {
    pair<int, int> k = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int nx = k.first + dx[i];
      int ny = k.second + dy[i];
      if (valid(nx, ny) && d[nx][ny] == -1) {
        d[nx][ny] = d[k.first][k.second] + 1;
        ans = max(ans, d[nx][ny]);
        que.push(make_pair(nx, ny));
      }
    }
  }
}
int main() {
  cin >> W >> H;
  getchar();
  for (int i = (0); i < (W); i++) {
    fgets(G[i], maxn, stdin);
  }
  for (int i = (0); i < (W); i++) {
    for (int j = (0); j < (H); j++) {
      memset(d, -1, sizeof(d));
      bfs(i, j);
    }
  }
  cout << ans << endl;
  return 0;
}
