#include <bits/stdc++.h>
using namespace std;
string ho[111];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> ho[i];
  }
  long long ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (ho[i][j] == '#') continue;
      for (int ii = 0; ii < h; ii++) {
        for (int jj = 0; jj < w; jj++) {
          if (ho[ii][jj] == '#') continue;
          bool vis[h + 1][w + 1];
          for (int iii = 0; iii < h; iii++)
            for (int jjj = 0; jjj < w; jjj++) vis[iii][jjj] = false;
          queue<tuple<long long, long long, long long>> que;
          que.push(make_tuple(i, j, 0));
          while (!que.empty()) {
            long long x, y, t;
            tie(x, y, t) = que.front();
            que.pop();
            if (x == ii && y == jj) {
              ans = max(ans, t);
              break;
            }
            if (x + 1 < h) {
              if (ho[x + 1][y] == '.' && vis[x + 1][y] == false) {
                vis[x + 1][y] = true;
                que.push(make_tuple(x + 1, y, t + 1));
              }
            }
            if (y + 1 < w) {
              if (ho[x][y + 1] == '.' && vis[x][y + 1] == false) {
                vis[x][y + 1] = true;
                que.push(make_tuple(x, y + 1, t + 1));
              }
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
