#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const int INF = 1 << 30;
const int dy[4] = {0, 0, 1, -1};
const int dx[4] = {1, -1, 0, 0};
int R, C, sy, sx, gy, gx;
vector<string> graph;
int hosuu[22][22];
int main() {
  cin >> R >> C;
  graph.resize(R);
  for (int i = 0; i < (int)(R); i++) {
    cin >> graph[i];
  }
  vector<pair<int, int> > res(0);
  for (int i = 0; i < (int)(R); i++) {
    for (int j = 0; j < (int)(C); j++) {
      if (graph[i][j] == '.') {
        res.push_back(make_pair(i, j));
      }
    }
  }
  int ans = 0;
  for (int k = 0; k < res.size(); k++) {
    for (int i = 0; i < (int)(R); i++)
      for (int j = 0; j < (int)(C); j++) hosuu[i][j] = 0;
    int sy = res[k].first;
    int sx = res[k].second;
    queue<pair<int, int> > q;
    q.push(make_pair(sy, sx));
    while (!q.empty()) {
      int y, x;
      tie(y, x) = q.front();
      q.pop();
      for (int dir = 0; dir < (int)(4); dir++) {
        int ny = y + dy[dir];
        int nx = x + dx[dir];
        if (0 <= ny && ny < R && 0 <= nx && nx < C &&
            graph.at(ny).at(nx) == '.' && hosuu[ny][nx] == 0) {
          hosuu[ny][nx] = hosuu[y][x] + 1;
          q.push(make_pair(ny, nx));
        }
      }
    }
    for (int i = 0; i < (int)(R); i++) {
      for (int j = 0; j < (int)(C); j++) {
        if (hosuu[i][j] > ans) ans = hosuu[i][j];
      }
    }
  }
  cout << ans << endl;
}
