#include <bits/stdc++.h>
using namespace std;
long double PI = 3.14159265358979323846;
const long long modo = 1e9 + 7;
const long long inf = 2e14;
const long long ms = (1e5) + 5;
int x, y;
int ar[30][30];
int vis[30][30];
int dis[30][30];
bool check(int i, int j) {
  if (i >= 1 && i <= x && j >= 1 && j <= y && !vis[i][j] && ar[i][j])
    return true;
  return false;
}
int func(int i, int j, int a, int b) {
  vis[i][j] = 1;
  dis[i][j] = dis[a][b] + 1;
  return dis[i][j];
}
int callme(int i, int j) {
  queue<pair<int, int>> qq;
  qq.push({i, j});
  int a, b;
  int mx = 0;
  while (!qq.empty()) {
    auto it = qq.front();
    qq.pop();
    a = it.first;
    b = it.second;
    if (check(a - 1, b)) {
      mx = max(func(a - 1, b, a, b), mx);
      qq.push({a - 1, b});
    }
    if (check(a + 1, b)) {
      mx = max(mx, func(a + 1, b, a, b));
      qq.push({a + 1, b});
    }
    if (check(a, b - 1)) {
      mx = max(mx, func(a, b - 1, a, b));
      qq.push({a, b - 1});
    }
    if (check(a, b + 1)) {
      mx = max(mx, func(a, b + 1, a, b));
      qq.push({a, b + 1});
    }
  }
  return mx;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  cin >> x >> y;
  int i;
  int j;
  char e;
  for (i = 1; i <= x; i++) {
    for (j = 1; j <= y; j++) {
      cin >> e;
      if (e == '.')
        ar[i][j] = 1;
      else
        ar[i][j] = 0;
    }
  }
  int ans = 0;
  for (i = 1; i <= x; i++) {
    for (j = 1; j <= y; j++) {
      if (ar[i][j]) {
        memset(vis, 0, sizeof(vis));
        memset(dis, 0, sizeof(dis));
        ans = max(ans, callme(i, j));
      }
    }
  }
  cout << ans;
  return 0;
}
