#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MX = 2e5 + 5;
const long long INF = 1e18;
const long double PI = 4 * atan((long double)1);
long long power(long long a, long long n) {
  long long res = 1;
  while (n) {
    if (n % 2) res *= a;
    a *= a;
    n /= 2;
  }
  return res;
}
long long abst(long long a) { return ((a < 0) ? (-1 * a) : (a)); }
int bfs(int s, vector<int> v[], int r, int c) {
  int vis[r * c + 1];
  queue<int> q;
  for (int i = 1; i <= (r * c); i++) vis[i] = -1;
  q.push(s);
  vis[s] = 0;
  while (!q.empty()) {
    int r = q.front();
    q.pop();
    for (int i = 0; i < v[r].size(); i++) {
      int ch = v[r][i];
      if (vis[ch] == -1) {
        vis[ch] = vis[r] + 1;
        q.push(ch);
      }
    }
  }
  int max = 0;
  for (int i = 1; i <= r * c; i++) {
    if (vis[i] > max) max = vis[i];
  }
  return max;
}
int main() {
  int r, c;
  cin >> r >> c;
  char arr[r + 1][c + 1];
  for (int i = 1; i <= r; i++)
    for (int j = 1; j <= c; j++) cin >> arr[i][j];
  int maxn = 0;
  vector<int> v[r * c + 1];
  for (int i = 1; i <= r; i++) {
    for (int j = 1; j <= c; j++) {
      int key = c * (i - 1) + j;
      if (i != 1) {
        if (arr[i - 1][j] != '#') {
          int k1 = c * (i - 2) + j;
          v[key].push_back(k1);
        }
      }
      if (i != r) {
        if (arr[i + 1][j] != '#') {
          int k1 = c * (i) + j;
          v[key].push_back(k1);
        }
      }
      if (j != 1) {
        if (arr[i][j - 1] != '#') {
          int k1 = c * (i - 1) + j - 1;
          v[key].push_back(k1);
        }
      }
      if (j != c) {
        if (arr[i][j + 1] != '#') {
          int k1 = c * (i - 1) + j + 1;
          v[key].push_back(k1);
        }
      }
    }
  }
  for (int i = 1; i <= (r * c); i++) {
    int tmp = bfs(i, v, r, c);
    if (tmp > maxn) maxn = tmp;
  }
  cout << maxn << "\n";
  return 0;
}
