#include <bits/stdc++.h>
using namespace std;
void chmin(int *a, int *b) {
  if (*a > *b + 1) {
    *a = *b + 1;
  }
}
int main(void) {
  int H, W;
  cin >> H >> W;
  vector<vector<bool>> S(H, vector<bool>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char a;
      cin >> a;
      if (a == '#') {
        S[i][j] = 0;
      } else {
        S[i][j] = 1;
      }
    }
  }
  int max = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      while (1) {
        if (S[i][j] == 0) break;
        vector<vector<int>> dp(H, vector<int>(W, 1000000));
        dp[i][j] = 0;
        int count = 0;
        while (count < H * W) {
          for (int m = 0; m < H; m++) {
            for (int n = 0; n < W; n++) {
              if (m - 1 >= 0 && S[m - 1][n] == 1) {
                chmin(&dp[m - 1][n], &dp[m][n]);
              }
              if (m + 1 < H && S[m + 1][n] == 1) {
                chmin(&dp[m + 1][n], &dp[m][n]);
              }
              if (n - 1 >= 0 && S[m][n - 1] == 1) {
                chmin(&dp[m][n - 1], &dp[m][n]);
              }
              if (n + 1 < W && S[m][n + 1] == 1) {
                chmin(&dp[m][n + 1], &dp[m][n]);
              }
              cout << right << setw(7) << dp[m][n] << " ";
            }
            cout << endl;
          }
          cout << endl;
          count++;
        }
        for (int k = 0; k < H; k++) {
          for (int l = 0; l < W; l++) {
            if (max < dp[k][l] && dp[k][l] != 1000000) {
              max = dp[k][l];
            }
          }
        }
        cout << endl;
        break;
      }
    }
  }
  cout << max << endl;
}
