#include <bits/stdc++.h>
using namespace std;
int h, w;
int plus_x[4] = {1, 0, -1, 0};
int plus_y[4] = {0, -1, 0, 1};
queue<pair<int, int> > que;
char s[20][20];
int ans[20][20];
void bfs(int x, int y) {
  int ans_field[h][w];
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ans_field[i][j] = -1;
    }
  }
  que.push(make_pair(x, y));
  ans_field[x][y] = 0;
  while (que.size()) {
    pair<int, int> p;
    p = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      x = p.first + plus_x[i];
      y = p.second + plus_y[i];
      if (x >= 0 && x < h && y >= 0 && y < w) {
        if (ans_field[x][y] == -1 && s[x][y] == '.') {
          que.push(make_pair(x, y));
          ans[x][y] = max(ans[x][y], ans_field[p.first][p.second] + 1);
          ans_field[x][y] = ans_field[p.first][p.second] + 1;
        }
      }
    }
  }
}
int main() {
  freopen("in.txt", "r", stdin);
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
      ans[i][j] = 0;
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '.') {
        bfs(i, j);
      }
    }
  }
  int answer = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << "x: " << i << " y: " << j << " max: " << ans[i][j] << endl;
      answer = max(answer, ans[i][j]);
    }
  }
  cout << answer << endl;
}
