#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const long long MOD = 1000000007;
const int INF = 1 << 29;
struct Corr {
  long long y;
  long long x;
  long long depth;
};
vector<string> vec;
queue<Corr> q;
vector<int> x_vec = {0, 0, +1, -1};
vector<int> y_vec = {+1, -1, 0, 0};
long long h, w;
long long s_y, s_x, g_y, g_x;
long long y, x, depth;
map<long long, long long> depth_cnt;
long long bfs() {
  while (!q.empty()) {
    Corr now = q.front();
    q.pop();
    y = now.y, x = now.x, depth = now.depth;
    depth_cnt[now.depth]++;
    if (y == g_y && x == g_x) return depth;
    for (long long i = 0; i < 4; ++i) {
      Corr next = {y + y_vec[i], x + x_vec[i], depth + 1};
      if (0 <= next.y && next.y <= h - 1 && 0 <= next.x && next.x <= w - 1 &&
          vec[next.y][next.x] == '.') {
        vec[next.y][next.x] = 'x';
        q.push(next);
      }
    }
  }
  return 0;
}
int main() {
  cin >> h >> w;
  vec.resize(h);
  for (int i = 0; i < h; i++) cin >> vec[i];
  vector<vector<int>> tmp_vec(h, vector<int>(w));
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) tmp_vec[i][j] = vec[i][j];
  long long res = 0;
  long long tmp = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      for (int m = 0; m < h; ++m) {
        for (int l = 0; l < w; ++l) {
          for (int u = 0; u < h; u++)
            for (int v = 0; v < w; v++) vec[u][v] = tmp_vec[u][v];
          s_y = i;
          s_x = j;
          Corr start = {s_y, s_x, 0};
          q.push(start);
          g_y = m;
          g_x = l;
          tmp = bfs();
          while (!q.empty()) q.pop();
          res = max(res, tmp);
        }
      }
    }
  }
  cout << res << endl;
}
