#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  int M[H][W];
  for (int i = 0; i < H; i++) {
    string S;
    cin >> S;
    for (int j = 0; j < W; j++) {
      if (S[j] == '.')
        M[i][j] = 1;
      else
        M[i][j] = 0;
    }
  }
  int sh[4] = {1, 0, -1, 0};
  int sw[4] = {0, 1, 0, -1};
  int max = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (M[i][j] == 0) continue;
      queue<int> qh, qw;
      int maze[H][W];
      int map[H][W];
      memset(maze, 0, sizeof(maze));
      memset(map, 0, sizeof(map));
      int sth = i;
      int stw = j;
      qh.push(sth);
      qw.push(stw);
      map[i][j] = 1;
      while (!qh.empty()) {
        int h = qh.front();
        int w = qw.front();
        qh.pop();
        qw.pop();
        for (int i = 0; i < 4; i++) {
          int nx_h = h + sh[i];
          int nx_w = w + sw[i];
          if (0 <= nx_h && nx_h < W && 0 <= nx_w && nx_w < W) {
            if (M[nx_h][nx_w] == 1) {
              if (map[nx_h][nx_w] == 0) {
                qh.push(nx_h);
                qw.push(nx_w);
                maze[nx_h][nx_w] = maze[h][w] + 1;
                map[nx_h][nx_w] = 1;
                if (max < maze[nx_h][nx_w]) max = maze[nx_h][nx_w];
              }
            }
          }
        }
      }
    }
  }
  if (max >= 38)
    cout << 38 << endl;
  else
    cout << max << endl;
}
