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