#include <bits/stdc++.h>
using namespace std;
char field[22][22];
int H, W;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int ans = 1e9, rans = 0;
bool d[22][22] = {};
queue<pair<int, int>> q;
queue<int> qq;
int main(void) {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> field[i][j];
    }
  }
  bool f[22][22] = {0};
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (field[i][j] == '.') {
        ans = 0;
        for (int k = 0; k <= H; k++)
          for (int kk = 0; kk <= W; kk++) d[k][kk] = 0;
        pair<int, int> tem;
        int c;
        q.push(pair<int, int>(i, j));
        qq.push(0);
        while (!q.empty()) {
          tem = q.front();
          c = qq.front();
          ans = max(ans, c);
          q.pop();
          qq.pop();
          d[tem.first][tem.second] = 1;
          int x = tem.first;
          int y = tem.second;
          for (int s = 0; s < 4; s++) {
            int xx = x + dx[s], yy = y + dy[s];
            if (xx >= 0 && yy >= 0 && xx < H && yy < W) {
              if (field[xx][yy] == '#') continue;
              if (d[xx][yy] == 1) continue;
              if (field[xx][yy] == '.' && d[xx][yy] == 0) {
                q.push(pair<int, int>(xx, yy));
                qq.push(c + 1);
              }
            }
          }
        }
        if (ans > rans) rans = ans;
      }
    }
  }
  cout << rans << endl;
  return 0;
}
