#include <bits/stdc++.h>
using namespace std;
void go();
int main() {
  go();
  return 0;
}
struct node {
  int x, y, step;
  node(int xx, int yy, int st) : x(xx), y(yy), step(st) {}
};
queue<node> que;
int n, m;
int vis[22][22];
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
string strs[40];
int ans;
int check(int x, int y) {
  return (x >= 0 && x < n && y >= 0 && y < m) && (!vis[x][y]) &&
         (strs[x][y] != '#');
}
void bfs(int i, int j) {
  memset(vis, 0, sizeof(vis));
  node st = node(i, j, 0);
  vis[st.x][st.y] = 1;
  que.push(st);
  while (!que.empty()) {
    st = que.front();
    que.pop();
    ans = max(ans, st.step);
    vis[st.x][st.y] = 1;
    for (int i = 0; i < 4; ++i) {
      int tx = st.x + dx[i];
      int ty = st.y + dy[i];
      if (check(tx, ty)) {
        que.push(node(tx, ty, st.step + 1));
      }
    }
  }
}
void go() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> strs[i];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (strs[i][j] != '#') bfs(i, j);
    }
  }
  cout << ans << endl;
}
