#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  string S[H];
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  int d[H][W][H][W];
  for (int(tate1) = 0; (tate1) < (H); (tate1)++) {
    for (int(yoko1) = 0; (yoko1) < (W); (yoko1)++) {
      for (int(tate2) = 0; (tate2) < (H); (tate2)++) {
        for (int(yoko2) = 0; (yoko2) < (W); (yoko2)++) {
          d[tate1][yoko1][tate2][yoko2] = 100000000;
        }
      }
    }
  }
  for (int(tate1) = 0; (tate1) < (H); (tate1)++) {
    for (int(yoko1) = 0; (yoko1) < (W); (yoko1)++) {
      if (S[tate1][yoko1] == '#') continue;
      if (tate1 + 1 != H && S[tate1 + 1][yoko1] != '#') {
        d[tate1][yoko1][tate1 + 1][yoko1] = 1;
        d[tate1 + 1][yoko1][tate1][yoko1] = 1;
      }
      if (yoko1 + 1 != W && S[tate1][yoko1 + 1] != '#') {
        d[tate1][yoko1][tate1][yoko1 + 1] = 1;
        d[tate1][yoko1 + 1][tate1][yoko1] = 1;
      }
    }
  }
  for (int(tate1) = 0; (tate1) < (H); (tate1)++) {
    for (int(yoko1) = 0; (yoko1) < (W); (yoko1)++) {
      if (S[tate1][yoko1] == '#') continue;
      for (int(tate2) = 0; (tate2) < (H); (tate2)++) {
        for (int(yoko2) = 0; (yoko2) < (W); (yoko2)++) {
          if (S[tate2][yoko2] == '#') continue;
          for (int(tate3) = 0; (tate3) < (H); (tate3)++) {
            for (int(yoko3) = 0; (yoko3) < (W); (yoko3)++) {
              if (S[tate3][yoko3] == '#') continue;
              if (d[tate2][yoko2][tate3][yoko3] >
                  d[tate2][yoko2][tate1][yoko1] +
                      d[tate1][yoko1][tate3][yoko3]) {
                d[tate2][yoko2][tate3][yoko3] = d[tate2][yoko2][tate1][yoko1] +
                                                d[tate1][yoko1][tate3][yoko3];
              }
            }
          }
        }
      }
    }
  }
  int ans = 0;
  for (int(tate1) = 0; (tate1) < (H); (tate1)++) {
    for (int(yoko1) = 0; (yoko1) < (W); (yoko1)++) {
      if (S[tate1][yoko1] == '#') continue;
      for (int(tate2) = 0; (tate2) < (H); (tate2)++) {
        for (int(yoko2) = 0; (yoko2) < (W); (yoko2)++) {
          if (S[tate2][yoko2] == '#') continue;
          ans = max(ans, d[tate1][yoko1][tate2][yoko2]);
        }
      }
    }
  }
  cout << ans << endl;
}
