#include <bits/stdc++.h>
using namespace std;
int main() {
  int r, c;
  int max = 0;
  char m[51][51];
  queue<int> bfs;
  queue<int> bfs1;
  int bfs2[50][50] = {0};
  int b1[4] = {0, 0, 1, -1};
  int b2[4] = {1, -1, 0, 0};
  cin >> r >> c;
  for (int a = 0; a < r; a++) {
    for (int b = 0; b < c; b++) {
      cin >> m[b][a];
    }
  }
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      if (m[j][i] == '#') {
        continue;
      } else {
        bfs.push(j);
        bfs1.push(i);
      }
      while (!bfs.empty()) {
        for (int i = 0; i < 4; i++) {
          if (m[bfs.front() + b1[i]][bfs1.front() + b2[i]] == '.' &&
              bfs2[bfs.front() + b1[i]][bfs1.front() + b2[i]] == 0) {
            bfs.push(bfs.front() + b1[i]);
            bfs1.push(bfs1.front() + b2[i]);
            bfs2[bfs.front() + b1[i]][bfs1.front() + b2[i]] =
                bfs2[bfs.front()][bfs1.front()] + 1;
            if (bfs2[bfs.front() + b1[i]][bfs1.front() + b2[i]] > max) {
              max = bfs2[bfs.front() + b1[i]][bfs1.front() + b2[i]];
            }
          }
        }
        bfs.pop();
        bfs1.pop();
      }
      for (int c = 0; c < 50; c++) {
        for (int d = 0; d < 50; d++) {
          bfs2[d][c] = 0;
        }
      }
    }
  }
  cout << max << endl;
}
