#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int H, W;
vector<string> field(20);
vector<vector<bool>> seen(20, vector<bool>(20, false));
vector<vector<int>> first_order(20, vector<int>(20, 0));
void dfs(int &ptr, int h, int w) {
  seen[h][w] = true;
  first_order.at(h).at(w) = ptr;
  for (int dir = 0; dir < 4; ++dir) {
    int nh = h + dx[dir];
    int nw = w + dy[dir];
    if (nh < 0 || nh >= H || nw < 0 || nw >= W) {
      continue;
    }
    if (field[nh][nw] == '#') {
      continue;
    }
    if (seen[nh][nw]) {
      continue;
    }
    ptr++;
    dfs(ptr, nh, nw);
  }
}
int main() {
  cin >> H >> W;
  for (int i = 0; i < (int)(H); i++) cin >> field[i];
  int sh, sw, gh, gw;
  int max = -1;
  for (int i = 0; i < (int)(H); i++) {
    for (int j = 0; j < (int)(W); j++) {
      if (field[i][j] == '.') {
        sh = i;
        sw = j;
        for (int k = 0; k < (int)(H); k++) {
          for (int l = 0; l < (int)(W); l++) {
            if (field[k][l] == '.') {
              int ptr = 0;
              gh = k;
              gw = l;
              dfs(ptr, sh, sw);
              if (seen[gh][gw]) {
                if (max < first_order.at(gh).at(gw)) {
                  max = first_order.at(gh).at(gw);
                }
              }
            }
          }
        }
      }
    }
  }
  cout << max << endl;
}
