#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;
}
const int MOD = 1e9 + 7;
long long s[100][100], h, w;
vector<long long> mp(long long a, long long b, long long cnt) {
  vector<long long> tmp(3);
  tmp[0] = a;
  tmp[1] = b;
  tmp[2] = cnt;
  return tmp;
}
int bfs(long long hi, long long wi) {
  vector<vector<long long>> m;
  m.resize(30);
  for (int i = 0; i < 30; i++) {
    m[i].resize(30, -1);
  }
  long long cnt = 0;
  queue<vector<long long>> q;
  q.push(mp(hi, wi, 0));
  while (!q.empty()) {
    vector<long long> p = q.front();
    q.pop();
    cnt = p[2];
    m[p[0]][p[1]] = cnt;
    long long x, y;
    x = p[0] - 1;
    y = p[1];
    if (x >= 0 && y >= 0 && x < h && y < w && s[x][y] == 0 && m[x][y] == -1) {
      q.push(mp(x, y, cnt + 1));
    }
    x = p[0] + 1;
    y = p[1];
    if (x >= 0 && y >= 0 && x < h && y < w && s[x][y] == 0 && m[x][y] == -1) {
      q.push(mp(x, y, cnt + 1));
    }
    x = p[0];
    y = p[1] - 1;
    if (x >= 0 && y >= 0 && x < h && y < w && s[x][y] == 0 && m[x][y] == -1) {
      q.push(mp(x, y, cnt + 1));
    }
    x = p[0];
    y = p[1] + 1;
    if (x >= 0 && y >= 0 && x < h && y < w && s[x][y] == 0 && m[x][y] == -1) {
      q.push(mp(x, y, cnt + 1));
    }
  }
  return cnt;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> w;
  for (long long hi = (0); hi < (long long)(h); ++hi) {
    string row;
    cin >> row;
    for (long long wi = (0); wi < (long long)(w); ++wi) {
      s[hi][wi] = row[wi] == '.' ? 0 : 1;
    }
  }
  long long ma = 0;
  for (long long hi = (0); hi < (long long)(h); ++hi) {
    for (long long wi = (0); wi < (long long)(w); ++wi) {
      if (s[hi][wi] == 0) {
        long long cost = bfs(hi, wi);
        chmax(ma, cost);
      }
    }
  }
  cout << fixed << ma;
  return 0;
}
