#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool upmin(T &x, T y) {
  return y < x ? x = y, 1 : 0;
}
template <typename T>
inline bool upmax(T &x, T y) {
  return x < y ? x = y, 1 : 0;
}
const long double eps = 1e-11;
const long double pi = acos(-1);
const int oo = 1 << 30;
const long long loo = 1ll << 62;
const int mods = 998244353;
const int MAXN = 105;
const int INF = 0x3f3f3f3f;
inline int read() {
  int f = 1, x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
char st[MAXN];
vector<pair<int, int> > V[MAXN];
int n, m, flag[MAXN][MAXN], vis[MAXN][MAXN];
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
int bfs(int x1, int y1, int x2, int y2) {
  for (int i = 0; i <= n * m; i++) V[i].clear();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) vis[i][j] = 0;
  V[0].push_back(make_pair(x1, y1));
  for (int i = 0; i <= n * m; i++)
    for (auto v : V[i]) {
      if (v.first == x2 && v.second == y2) return i;
      if (vis[v.first][v.second]) continue;
      vis[v.first][v.second] = 1;
      for (int j = 0; j < 4; j++) {
        int xx = v.first + dx[j], yy = v.second + dy[j];
        if (xx > 0 && yy > 0 && xx <= n && yy <= m && flag[xx][yy] &&
            !vis[xx][yy])
          V[i + 1].push_back(make_pair(xx, yy));
      }
    }
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= n; i++) {
    scanf("%s", st + 1);
    for (int j = 1; j <= m; j++) flag[i][j] = (st[j] == '.') ? 1 : 0;
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (flag[i][j])
        for (int k = 1; k <= n; k++)
          for (int t = 1; t <= m; t++)
            if (flag[k][t]) {
              int p = bfs(i, j, k, t);
              upmax(ans, p);
            }
  printf("%d\n", ans);
  return 0;
}
