#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
const long long inf = 100;
using namespace std;
vector<string> matrix;
long long h, w;
long long V;
void fast_io() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void printSolution(long long dist[400][400]) {
  long long m = -1;
  for (long long i = 0; i < V; i++)
    for (long long j = 0; j < V; j++)
      if (dist[i][j] != inf) m = max(m, dist[i][j]);
  cout << m << "\n";
}
void floydWarshall(long long graph[400][400]) {
  long long dist[400][400], i, j, k;
  for (i = 0; i < V; i++)
    for (j = 0; j < V; j++) dist[i][j] = graph[i][j];
  for (k = 0; k < V; k++) {
    for (i = 0; i < V; i++) {
      for (j = 0; j < V; j++) {
        if (dist[i][k] + dist[k][j] < dist[i][j])
          dist[i][j] = dist[i][k] + dist[k][j];
      }
    }
  }
  printSolution(dist);
}
signed main() {
  fast_io();
  cin >> h >> w;
  long long g[400][400];
  for (long long i = 0; i < 400; i++)
    for (long long j = 0; j < 400; j++) g[i][j] = inf;
  V = h * w;
  matrix.resize(h);
  for (long long i = 0; i < h; i++) cin >> matrix[i];
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      if (matrix[i][j] == '.') {
        long long n = i * w + j;
        g[n][n] = 1;
        if (i >= 1)
          if (matrix[i - 1][j] == '.') {
            g[n - w][n] = g[n][n - w] = 1;
          }
        if (i <= h - 2)
          if (matrix[i + 1][j] == '.') {
            g[n + w][n] = g[n][n + w] = 1;
          }
        if (j >= 1)
          if (matrix[i][j - 1] == '.') {
            g[n - 1][n] = g[n][n - 1] = 1;
          }
        if (j <= w - 2)
          if (matrix[i][j + 1] == '.') {
            g[n + 1][n] = g[n][n + 1] = 1;
          }
      }
    }
  }
  floydWarshall(g);
  return 0;
}
