#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
char maze[30][30];
int d[30][30];
int h, w;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
int bfs(int now_h, int now_w) {
  queue<pair<int, int>> que;
  bool visited[h][w];
  for (int i = (int)(0); i < (int)(h); ++i)
    for (int j = (int)(0); j < (int)(w); ++j) visited[i][j] = false;
  que.push(make_pair(now_h, now_w));
  while (!que.empty()) {
    pair<int, int> p = que.front();
    que.pop();
    visited[p.first][p.second] = true;
    for (int i = (int)(0); i < (int)(4); ++i) {
      int tmpx = p.first + dx[i];
      int tmpy = p.second + dy[i];
      if (visited[tmpx][tmpy] == false && 0 <= tmpx && tmpx < h && 0 <= tmpy &&
          tmpy < w && maze[tmpx][tmpy] == '.') {
        d[tmpx][tmpy] = d[p.first][p.second] + 1;
        que.push(make_pair(tmpx, tmpy));
      }
    }
  }
  int dmax = 0;
  for (int i = (int)(0); i < (int)(h); ++i)
    for (int j = (int)(0); j < (int)(w); ++j) dmax = max(dmax, d[i][j]);
  return dmax;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> h >> w;
  for (int i = (int)(0); i < (int)(h); ++i)
    for (int j = (int)(0); j < (int)(w); ++j) cin >> maze[i][j];
  int dmax = 0;
  for (int i = (int)(0); i < (int)(h); ++i)
    for (int j = (int)(0); j < (int)(w); ++j) {
      if (maze[i][j] != '.') continue;
      for (int k = (int)(0); k < (int)(h); ++k)
        for (int l = (int)(0); l < (int)(w); ++l) d[k][l] = -1;
      d[i][j] = 0;
      dmax = max(dmax, bfs(i, j));
    }
  cout << dmax << endl;
}
