#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int checkaround(int H, int W, vector<vector<int>> M, pair<int, int> now,
                vector<vector<int>> &cost, vector<vector<int>> &arrival) {
  int tate = now.first;
  int yoko = now.second;
  if (M[tate][yoko] == -1) {
    return 0;
  }
  arrival[tate][yoko] = 1;
  if (tate >= 1 && M[tate - 1][yoko] != -1) {
    if (cost[tate - 1][yoko] > cost[tate][yoko] + 1) {
      cost[tate - 1][yoko] = cost[tate][yoko] + 1;
    }
  }
  if (H - tate - 1 >= 1 && M[tate + 1][yoko] != -1) {
    if (cost[tate + 1][yoko] > cost[tate][yoko] + 1) {
      cost[tate + 1][yoko] = cost[tate][yoko] + 1;
    }
  }
  if (yoko >= 1 && M[tate][yoko - 1] != -1) {
    if (cost[tate][yoko - 1] > cost[tate][yoko] + 1) {
      cost[tate][yoko - 1] = cost[tate][yoko] + 1;
    }
  }
  if (W - yoko - 1 >= 1 && M[tate][yoko + 1] != -1) {
    if (cost[tate][yoko + 1] > cost[tate][yoko] + 1) {
      cost[tate][yoko + 1] = cost[tate][yoko] + 1;
    }
  }
  int costmin = INT_MAX;
  pair<int, int> Nextp;
  for (int i = 0; i < (H); i++) {
    for (int j = 0; j < (W); j++) {
      if (arrival[i][j] != 1 && M[i][j] != -1) {
        if (costmin > cost[i][j]) {
          costmin = cost[i][j];
          Nextp = make_pair(i, j);
        }
      }
    }
  }
  if (costmin != INT_MAX) {
    checkaround(H, W, M, Nextp, cost, arrival);
  }
  return 0;
}
int STpath(int H, int W, vector<vector<int>> M, pair<int, int> S,
           pair<int, int> T) {
  vector<vector<int>> cost(H, vector<int>(W, INT_MAX));
  vector<vector<int>> arrival(H, vector<int>(W, -1));
  cost[S.first][S.second] = 0;
  checkaround(H, W, M, S, cost, arrival);
  int costmax = 0;
  for (int i = 0; i < (H); i++) {
    for (int j = 0; j < (W); j++) {
      if (costmax < cost[i][j] && cost[i][j] != INT_MAX) {
        costmax = cost[i][j];
      }
    }
  }
  return costmax;
}
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> M(H, vector<int>(W));
  for (int i = 0; i < (H); i++) {
    for (int j = 0; j < (W); j++) {
      char S;
      cin >> S;
      if (S == '.') {
        M[i][j] = 1;
      } else if (S == '#') {
        M[i][j] = -1;
      }
    }
  }
  int maxcost = 0;
  for (int i = 0; i < (H); i++) {
    for (int j = 0; j < (W); j++) {
      for (int k = 0; k < (H); k++) {
        for (int l = 0; l < (W); l++) {
          int cost = STpath(H, W, M, make_pair(i, j), make_pair(k, l));
          if (cost > maxcost) {
            maxcost = cost;
          }
        }
      }
    }
  }
  cout << maxcost << endl;
  return 0;
}
