#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7, MAx = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W,
    x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAx, min_index = -1;
int main() {
  cin >> H >> W;
  char maze[20][20];
  long long value[20][20];
  max_value = 0;
  for (int i = 0; i < (int)(H); i++) {
    for (int j = 0; j < (int)(W); j++) {
      cin >> maze[i][j];
    }
  }
  int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
  for (int i = 0; i < (int)(H); i++) {
    for (int j = 0; j < (int)(W); j++) {
      if (maze[i][j] == '#')
        continue;
      else {
        for (int k = 0; k < (int)(20); k++) {
          for (int l = 0; l < (int)(20); l++) {
            value[k][l] = -1;
          }
        }
        queue<pair<long long, long long> > que;
        value[i][j] = 0;
        que.push(make_pair(i, j));
        while (!que.empty()) {
          pair<long long, long long> curr = que.front();
          que.pop();
          for (int k = 0; k < (int)(4); k++) {
            int y = curr.first + dy[k], x = curr.second + dx[k];
            if (y < 0 || y >= H || x < 0 || x >= W) continue;
            if (maze[y][x] == '#' || value[y][x] > 0) continue;
            que.push(make_pair(y, x));
            value[y][x] = value[curr.first][curr.second] + 1;
          }
        }
        for (int k = 0; k < (int)(H); k++) {
          for (int l = 0; l < (int)(W); l++) {
            max_value = max(value[k][l], max_value);
          }
        }
      }
    }
  }
  cout << max_value;
}
