#include <bits/stdc++.h>
using namespace std;
template <class T>
using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;
template <class T>
pair<T, size_t> max(vector<T> &x) {
  auto it = max_element((x).begin(), (x).end());
  return make_pair(*it, it - x.begin());
}
template <class T>
pair<T, size_t> min(vector<T> &x) {
  auto it = min_element((x).begin(), (x).end());
  return make_pair(*it, it - x.begin());
}
template <class T>
inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int visited[20][20];
int dist[20][20];
void init() {
  for (int i = int(0); i < int(20); ++i) {
    for (int j = int(0); j < int(20); ++j) {
      visited[i][j] = 0;
      dist[i][j] = 9999;
    }
  }
}
ll far_dist(vector<string> &maze, int h, int w) {
  init();
  int H = maze.size();
  int W = maze[0].size();
  dist[h][w] = 0;
  queue<tuple<int, int, int>> q;
  q.push(make_tuple(h, w, dist[h][w]));
  int i, j, d;
  while (!q.empty()) {
    tie(i, j, d) = q.front();
    q.pop();
    visited[i][j] = 1;
    for (int k = int(0); k < int(4); ++k) {
      int x = i + dx[k];
      int y = j + dy[k];
      if (0 <= (y) && (y) < (W) && 0 <= (x) && (x) < (H) && maze[x][y] == '.' &&
          visited[x][y] == 0) {
        q.push(make_tuple(x, y, d + 1));
      }
    }
  }
  return d;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<string> maze;
  for (int h = int(0); h < int(H); ++h) {
    string line;
    cin >> line;
    maze.push_back(line);
  }
  ll ret = 0;
  for (int h = int(0); h < int(H); ++h) {
    for (int w = int(0); w < int(W); ++w) {
      if (maze[h][w] == '.') {
        ret = max(ret, far_dist(maze, h, w));
      }
    }
  }
  cout << ret << endl;
  return 0;
}
