#include <bits/stdc++.h>
using namespace std;
class solution {
 public:
  int vertices = 0;
  vector<int> positions;
  vector<int> distance;
  vector<int> adj[402];
  void add(int u, int v) { adj[u].push_back(v); }
  char mat[20][20];
  void solve() {
    int w, h;
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        cin >> mat[i][j];
        vertices++;
      }
    }
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (mat[i][j] == '.') {
          if (i - 1 >= 0) {
            if (mat[i - 1][j] == '.') {
              add(i * w + j + 1, (i - 1) * w + j + 1);
            }
          }
          if (i + 1 >= 0) {
            if (mat[i + 1][j] == '.') {
              add(i * w + j + 1, (i + 1) * w + j + 1);
            }
          }
          if (j - 1 >= 0) {
            if (mat[i][j - 1] == '.') {
              add(i * w + j + 1, (i)*w + j);
            }
          }
          if (j + 1 >= 0) {
            if (mat[i][j + 1] == '.') {
              add(i * w + j + 1, (i)*w + j + 2);
            }
          }
        } else {
          positions.push_back(i * w + j + 1);
        }
      }
    }
    int ans = 0;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (mat[i][j] == '.') {
          distance.resize(h * w + 1, 0);
          for (auto it : positions) {
            distance[it] = -1;
          }
          distance[i * w + j + 1] = 0;
          bfs(i * w + j + 1);
          ans = max(ans, *max_element(distance.begin(), distance.end()));
        }
      }
    }
    cout << ans;
  }
  void bfs(int u) {
    queue<int> q;
    q.push(u);
    vector<bool> v(vertices + 1, false);
    v[u] = true;
    while (!q.empty()) {
      int first = q.front();
      q.pop();
      for (auto it : adj[first]) {
        if (!v[it]) {
          q.push(it);
          v[it] = true;
          distance[it] = distance[first] + 1;
        }
      }
    }
  }
};
int main() {
  ios::sync_with_stdio(0), cout.tie(0), cin.tie(0);
  long long i = 0;
  solution s;
  s.solve();
  return 0;
}
