#include <bits/stdc++.h>
using namespace std;
void print() { cout << endl; }
void prints() {}
template <typename T>
void get(T* x, long long int n) {
  for (long long int i = 0; i < n; ++i) {
    cin >> x[i];
  }
}
template <typename T>
void get(T& x, long long int n) {
  for (long long int i = 0; i < n; ++i) {
    cin >> x[i];
  }
}
template <typename T, typename... A>
void print(T x, A... r) {
  cout << x << " ";
  print(r...);
}
template <typename T, typename... A>
void prints(T x, A... r) {
  cout << x << " ";
  prints(r...);
}
const long long int mod = 1e9 + 7;
const long long int N = 21;
char grid[N][N];
long long int h, w;
long long int d[N * N][N * N];
bool bounds(long long int i, long long int j) {
  return 0 <= i && i <= h && j <= w && 0 <= j;
}
void flw() {
  for (long long int k = 0; k < N; ++k) {
    for (long long int i = 0; i < N; ++i) {
      for (long long int j = 0; j < N; ++j) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (long long int i = 0; i < N * N; ++i) {
    for (long long int j = 0; j < N * N; ++j) {
      d[i][j] = 1e9;
    }
  }
  for (long long int i = 0; i < N * N; ++i) {
    d[i][i] = 0;
  }
  cin >> h >> w;
  for (long long int i = 0; i < h; ++i) {
    for (long long int j = 0; j < w; ++j) {
      cin >> grid[i][j];
    }
  }
  long long int ans = 0;
  for (long long int i = 0; i < h; i++) {
    for (long long int j = 0; j < w; ++j) {
      if (grid[i][j] == '.') {
        vector<pair<long long ll, long long ll> > v = {
            {i, j + 1}, {i, j - 1}, {i + 1, j}, {i - 1, j}};
        for (auto p : v) {
          long long int x = p.first;
          long long int y = p.second;
          if (bounds(x, y) && grid[x][y] == '.') {
            long long int a = i * w + j;
            long long int b = x * w + y;
            d[a][b] = 1;
          }
        }
      }
    }
  }
  flw();
  for (long long int i = 0; i < h; i++) {
    for (long long int j = 0; j < w; ++j) {
      for (long long int x = 0; x < h; x++) {
        for (long long int y = 0; y < w; ++y) {
          if (grid[x][y] == '.' && grid[i][j] == '.') {
            long long int a = i * w + j;
            long long int b = x * w + y;
            ans = max(ans, d[a][b]);
          }
        }
      }
    }
  }
  print(ans);
  return 0;
}
