#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y, long long m) {
  long long r = 1;
  for (; y; y >>= 1) {
    if (y & 1) r = r * x % m;
    x = x * x % m;
  }
  return r;
}
const long long mod = 1e9 + 7;
const long double pi = 3.14159265358979;
int arr[21][21], visited[21][21], level[21][21], h, w;
int r[4] = {0, 1, -1, 0};
int c[4] = {1, 0, 0, -1};
int check(int i, int j) {
  if (i >= 0 && j >= 0 && i < h && j < w) return 1;
  return 0;
}
int dfs(int x, int y) {
  queue<int> q;
  int k = 0;
  q.push(x);
  q.push(y);
  while (!q.empty()) {
    int a = q.front();
    q.pop();
    int b = q.front();
    q.pop();
    visited[a][b] = 1;
    for (int i = 0; i < 4; i++) {
      if (arr[a + r[i]][b + c[i]] == 1 && check(a + r[i], b + c[i]) &&
          !visited[a + r[i]][b + c[i]]) {
        q.push(a + r[i]);
        q.push(b + c[i]);
        level[a + r[i]][b + c[i]] = level[a][b] + 1;
        k = max(k, level[a + r[i]][b + c[i]]);
      }
    }
  }
  return k;
}
int run_test() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char t;
      cin >> t;
      if (t == '#')
        arr[i][j] = 0;
      else {
        arr[i][j] = 1;
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      level[i][j] = visited[i][j] = 0;
    }
  }
  int k, l, m, ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (arr[i][j] == 1 && !visited[i][j]) {
        k = dfs(i, j);
        for (l = 0; l < h; l++) {
          for (m = 0; m < w; m++) {
            if (level[l][m] == k) {
              break;
            }
          }
        }
        for (int p = 0; p < h; p++) {
          for (int q = 0; q < w; q++) {
            level[p][q] = visited[p][q] = 0;
          }
        }
        k = dfs(l, m);
        ans = max(ans, k);
      }
    }
  }
  cout << ans - 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  srand(time(NULL));
  ;
  long long t;
  t = 1;
  while (t--) {
    run_test();
  }
}
