#include <bits/stdc++.h>
using namespace std;
int h, w, d[20][20], r[20][20], vx[4] = {0, 1, 0, -1}, vy[4] = {1, 0, -1, 0},
                                ans = 0;
char maze[20][20];
int bfs(int s, int t) {
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) d[i][j] = 0, r[i][j] = 0;
  queue<pair<int, int> > que;
  que.push(pair<int, int>(s, t));
  r[s][t] = 1;
  while (!que.empty()) {
    pair<int, int> v = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int x = v.first + vx[i], y = v.second + vy[i];
      if (maze[x][y] == '#' || r[x][y] || x < 0 || x >= h || y < 0 || y >= w)
        continue;
      r[x][y]++;
      d[x][y] = d[v.first][v.second] + 1;
      que.push(pair<int, int>(x, y));
    }
  }
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) ans = max(ans, d[i][j]);
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) cin >> maze[i][j];
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) bfs(i, j);
  cout << ans;
}
