#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9, MX = 1000007;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int x, int y) {
  x /= gcd(x, y);
  return x * y;
}
bool prime[MX], isprime[MX];
vector<int> v;
int cs = 0;
int fx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int fy[] = {0, 0, 1, -1, 1, -1, 1, -1};
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
char cell[25][25];
int vis[25][25], dis[25][25];
bool InRng(int i, int j, int m, int n) {
  return ((i >= 1 && i <= m) && (j >= 1 && j <= n) && cell[i][j] == '.');
}
struct A {
  int u, v, id;
  A(int a, int b, int c) { u = a, v = b, id = c; }
};
bool operator<(A a, A b) { return a.v > b.v; }
int bfs(int i, int j, int m, int n) {
  int cnt = 0;
  queue<pair<int, int> > Q;
  Q.push({i, j});
  vis[i][j] = 1;
  dis[i][j] = 0;
  while (Q.size()) {
    pair<int, int> ptr = Q.front();
    int u = ptr.first, v = ptr.second;
    Q.pop();
    for (int i = 0; i < 4; i++) {
      int x = u + fx[i];
      int y = v + fy[i];
      if (InRng(x, y, m, n) && !vis[x][y]) {
        vis[x][y] = 1;
        dis[x][y] = dis[u][v] + 1;
        Q.push({x, y});
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) cnt = max(dis[i][j], cnt);
  }
  return cnt;
}
int main() {
  int n, m, ans = 0;
  cin >> m >> n;
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) cin >> cell[i][j];
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      memset(dis, 0, sizeof dis);
      memset(vis, 0, sizeof vis);
      ans = max(ans, bfs(i, j, m, n));
    }
  }
  cout << ans << "\n";
  return 0;
}
