#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
int M[22][22];
int C[22][22];
queue<pair<int, int>> Q;
int H, W;
int mx, my;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
void drawC(int H, int W) {
  for (int y = 0; y < (H); y++) {
    for (int x = 0; x < (W); x++) {
      cout << setw(3) << C[y][x] << " ";
    }
    cout << endl;
  }
  cout << "----------------------" << endl;
  return;
}
int bfs(int h, int w) {
  int nmax = 0;
  C[h][w] = 0;
  Q.push(make_pair(h, w));
  while (!Q.empty()) {
    pair<int, int> t = Q.front();
    Q.pop();
    int tx = t.second;
    int ty = t.first;
    for (int i = 0; i < (4); i++) {
      int nx = tx + dx[i];
      int ny = ty + dy[i];
      if (M[ny][nx] == -1) {
        continue;
      }
      if (C[ny][nx] != -1) {
        continue;
      }
      C[ny][nx] = C[ty][tx] + 1;
      Q.push(make_pair(ny, nx));
    }
  }
  for (int i = 0; i < (H + 2); i++) {
    for (int j = 0; j < (W + 2); j++) {
      if (nmax < C[i][j]) {
        nmax = C[i][j];
        mx = j;
        my = i;
      }
    }
  }
  return nmax;
}
void draw(int H, int W) {
  for (int y = 0; y < (H + 2); y++) {
    for (int x = 0; x < (W + 2); x++) {
      cout << setw(3) << M[y][x] << " ";
    }
    cout << endl;
  }
  return;
}
void initC(void) {
  for (int i = 0; i < (22); i++) {
    for (int j = 0; j < (22); j++) {
      C[i][j] = -1;
    }
  }
}
void solve(void) {
  cin >> H >> W;
  for (int y = 0; y < (22); y++) {
    for (int x = 0; x < (22); x++) {
      if (x == 0 || x >= W + 1 || y == 0 || y >= H + 1) {
        M[y][x] = -1;
        continue;
      }
      char tmp;
      cin >> tmp;
      if (tmp == '.') {
        M[y][x] = 0;
        mx = x;
        my = y;
      }
      if (tmp == '#') {
        M[y][x] = -1;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < (H + 2); i++) {
    for (int j = 0; j < (W + 2); j++) {
      if (M[i][j] == 0) {
        initC();
        chmax(ans, bfs(j, i));
      }
    }
  }
  cout << ans << endl;
  return;
}
int main(int argc, const char* argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
