#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int x;
  scanf("%d", &x);
  return x;
}
template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
  for (int j = 0; j < ((int)(v).size()); ++j) i >> v[j];
  return i;
}
template <typename T>
string join(const vector<T>& v) {
  stringstream s;
  for (int i = 0; i < ((int)(v).size()); ++i) s << ' ' << v[i];
  return s.str().substr(1);
}
template <typename T>
inline ostream& operator<<(ostream& o, const vector<T>& v) {
  if ((int)(v).size()) o << join(v);
  return o;
}
template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}
template <typename T1, typename T2>
inline ostream& operator<<(ostream& o, const pair<T1, T2>& v) {
  return o << v.first << "," << v.second;
}
template <typename T>
inline long long int suma(const vector<T>& a) {
  long long int res(0);
  for (auto&& x : a) res += x;
  return res;
}
const double eps = 1e-10;
const long long int LINF = 1001002003004005006ll;
const int INF = 1001001001;
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int h, w;
char maze[25][25];
bool visited[25][25];
int rec(int sx, int sy, int tx, int ty) {
  if (sx == tx && sy == ty) return 0;
  visited[sy][sx] = true;
  int ans = INF;
  for (int i = 0; i < (4); ++i) {
    int nsx = sx + dx[i];
    int nsy = sy + dy[i];
    if (0 <= nsx && nsx < w && 0 <= nsy && nsy < h && !visited[nsy][nsx] &&
        maze[nsy][nsx] != '#')
      ans = min(rec(nsx, nsy, tx, ty) + 1, ans);
  }
  return ans;
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < (h); ++i)
    for (int j = 0; j < (w); ++j) cin >> maze[i][j];
  int ans = 0;
  for (int sy = 0; sy < (h); ++sy)
    for (int sx = 0; sx < (w); ++sx)
      for (int ty = 0; ty < (h); ++ty)
        for (int tx = 0; tx < (w); ++tx) {
          if (maze[sy][sx] != '#' && maze[ty][tx] != '#') {
            memset(visited, false, sizeof(visited));
            ans = max(rec(sx, sy, tx, ty), ans);
          }
        }
  cout << ans << endl;
  return 0;
}
