#include <bits/stdc++.h>
using namespace std;
char field[30][30];
int des[5000][5000];
int ans[5000][5000];
int main() {
  int H, W;
  cin >> H >> W;
  for (int x = 0; x < (30); x++) {
    for (int y = 0; y < (30); y++) {
      field[x][y] = '#';
    }
  }
  for (int x = 0; x < (H); x++) {
    string s;
    cin >> s;
    for (int y = 0; y < (W); y++) {
      field[x + 1][y + 1] = s[y];
    }
  }
  for (int x = 0; x < (H * 100 + W + 1); x++) {
    for (int z = 0; z < (H * 100 + W + 1); z++) {
      des[x][z] = INT_MAX / 2;
    }
  }
  for (int x = 0; x < (H); x++) {
    for (int y = 0; y < (W); y++) {
      if (field[x + 1][y + 1] == '#') {
        continue;
      }
      if (field[x + 2][y + 1] == '.') {
        des[(x + 1) * 100 + y + 1][(x + 2) * 100 + y + 1] = 1;
      }
      if (field[x][y + 1] == '.') {
        des[(x + 1) * 100 + y + 1][(x)*100 + y + 1] = 1;
      }
      if (field[x + 1][y + 2] == '.') {
        des[(x + 1) * 100 + y + 1][(x + 1) * 100 + y + 2] = 1;
      }
      if (field[x + 1][y] == '.') {
        des[(x + 1) * 100 + y + 1][(x + 1) * 100 + y] = 1;
      }
    }
  }
  for (int y = 0; y < (H * 100 + W + 1); y++) {
    for (int x = 0; x < (H * 100 + W + 1); x++) {
      for (int z = 0; z < (H * 100 + W + 1); z++) {
        des[x][z] = min(des[x][z], des[x][y] + des[y][z]);
      }
    }
  }
  int ans = 0;
  for (int x = 0; x < (H); x++) {
    for (int y = 0; y < (W); y++) {
      if (field[x + 1][y + 1] == '.') {
        for (int w = 0; w < (H); w++) {
          for (int z = 0; z < (W); z++) {
            if (x == w && y == z) {
              continue;
            }
            if (field[w + 1][z + 1] == '#') {
              continue;
            }
            ans = max(ans, des[(x + 1) * 100 + y + 1][(w + 1) * 100 + z + 1]);
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
