#include <bits/stdc++.h>
using namespace std;
struct LOC {
  LOC(int arg_row, int arg_col) {
    row = arg_row;
    col = arg_col;
  }
  int row, col;
};
int H, W;
int diff_row[4] = {-1, 0, 0, 1}, diff_col[4] = {0, -1, 1, 0};
char buf[25][25];
int table[25][25];
bool rangeCheck(int row, int col) {
  return row >= 0 && row <= H - 1 && col >= 0 && col <= W - 1;
}
int main() {
  scanf("%d %d", &H, &W);
  for (int row = 0; row < H; row++) {
    scanf("%s", buf[row]);
  }
  int maximum = 0;
  queue<LOC> Q;
  for (int st_row = 0; st_row < H; st_row++) {
    for (int st_col = 0; st_col < W; st_col++) {
      for (int row = 0; row < H; row++) {
        for (int col = 0; col < W; col++) {
          table[row][col] = 2000000000;
        }
      }
      table[st_row][st_col] = 0;
      Q.push(LOC(st_row, st_col));
      while (!Q.empty()) {
        for (int i = 0; i < 4; i++) {
          int adj_row = Q.front().row + diff_row[i];
          int adj_col = Q.front().col + diff_col[i];
          if (rangeCheck(adj_row, adj_col) == false ||
              buf[adj_row][adj_col] == '#')
            continue;
          int next_dist = table[Q.front().row][Q.front().col] + 1;
          if (table[adj_row][adj_col] <= next_dist) continue;
          table[adj_row][adj_col] = next_dist;
          Q.push(LOC(adj_row, adj_col));
        }
        Q.pop();
      }
      for (int row = 0; row < H; row++) {
        for (int col = 0; col < W; col++) {
          if (buf[row][col] == '#') continue;
          maximum = max(maximum, table[row][col]);
        }
      }
    }
  }
  printf("%d\n", maximum);
  return 0;
}
