#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int inf = -1;
char maze[20][20];
int d[20][20];
int ans[20][20];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int bfs(int w, int h, int sx, int sy) {
  queue<pair<int, int> > que;
  for (int i = 0; i < (20); ++i)
    for (int j = 0; j < (20); ++j) d[i][j] = inf;
  d[sx][sy] = 0;
  que.push(pair<int, int>(sx, sy));
  while (que.size()) {
    pair<int, int> pos = que.front();
    que.pop();
    for (int i = 0; i < (4); ++i) {
      int nx = pos.first + dx[i];
      int ny = pos.second + dy[i];
      if (nx >= 0 && nx < w && ny >= 0 && ny < h && maze[nx][ny] != '#' &&
          d[nx][ny] == inf) {
        que.push(pair<int, int>(nx, ny));
        d[nx][ny] = d[pos.first][pos.second] + 1;
      }
    }
  }
  int max = 0;
  for (int i = 0; i < (w); ++i) {
    for (int j = 0; j < (h); ++j) {
      if (max < d[i][j]) {
        max = d[i][j];
      }
    }
  }
  return max;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < (20); ++i) {
    for (int j = 0; j < (20); ++j) {
      ans[i][j] = -1;
      maze[i][j] = '#';
    }
  }
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (m); ++j) {
      char c;
      cin >> c;
      maze[j][i] = c;
    }
  }
  int res = 0;
  for (int i = 0; i < (n); ++i) {
    for (int j = 0; j < (m); ++j) {
      ans[i][j] = bfs(m, n, j, i);
      if (res < ans[i][j]) {
        res = ans[i][j];
      }
    }
  }
  cout << res << endl;
}
