#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int bfstable[20][20];
bool visited[20][20];
int h, w;
queue<pii> q;
pii start, goal;
int x[4] = {-1, 1, 0, 0};
int y[4] = {0, 0, -1, 1};
int bfs() {
  while (!q.empty()) {
    pii current = q.front();
    q.pop();
    if (current.first == goal.first && current.second == goal.second)
      return bfstable[goal.first][goal.second];
    pii next1(current.first + 1, current.second);
    if (next1.first < h && visited[next1.first][next1.second] == false) {
      chmin(bfstable[next1.first][next1.second],
            bfstable[current.first][current.second] + 1);
      q.push(next1);
    }
    pii next2(current.first, current.second + 1);
    if (next2.second < w) {
      chmin(bfstable[next2.first][next2.second],
            bfstable[current.first][current.second] + 1);
      q.push(next2);
    }
    pii next3(current.first - 1, current.second);
    if (next3.second >= 0) {
      chmin(bfstable[next3.first][next3.second],
            bfstable[current.first][current.second] + 1);
      q.push(next3);
    }
    pii next4(current.first, current.second - 1);
    if (next4.second >= 0) {
      chmin(bfstable[next4.first][next4.second],
            bfstable[current.first][current.second] + 1);
      q.push(next4);
    }
  }
  return 0;
}
int main() {
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < (int)(h); i++) cin >> s[i];
  int max = -1e9;
  for (int i = 0; i < (int)(h); i++)
    for (int j = 0; j < (int)(w); j++)
      for (int k = 0; k < (int)(h); k++)
        for (int l = 0; l < (int)(w); l++) {
          queue<pii> empty;
          swap(q, empty);
          start.first = i;
          start.second = j;
          goal.first = k;
          goal.second = l;
          q.push(start);
          cout << "i: " << i << " j:" << j << " k:" << k << " l:" << l << endl;
          if ((s[start.first][start.second] == '.') &&
              (s[goal.first][goal.second] == '.')) {
            for (int i = 0; i < (int)(20); i++)
              for (int j = 0; j < (int)(20); j++) {
                bfstable[i][j] = 1e9;
                visited[i][j] = false;
              }
            bfstable[start.first][start.second] = 0;
            bfs();
            cout << "max,temp: " << max << " "
                 << bfstable[goal.first][goal.second] << endl;
            chmax(max, bfstable[goal.first][goal.second]);
          }
        }
  cout << max << endl;
  return 0;
}
