#include <bits/stdc++.h>
using namespace std;
const long long inf = -12345;
const long long wall = -1234;
vector<string> vs;
int mp[21][21];
int h, w;
int bfs(pair<int, int> st) {
  queue<pair<int, int> > que;
  que.push(st);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (vs[i][j] != '#')
        mp[i][j] = inf;
      else
        mp[i][j] = wall;
    }
  }
  mp[st.first][st.second] = 0;
  int dx[4] = {0, 0, -1, 1};
  int dy[4] = {1, -1, 0, 0};
  while (que.size()) {
    pair<int, int> p = que.front();
    que.pop();
    for (int i = 0; i < 4; i++) {
      int sy = p.first + dy[i];
      int sx = p.second + dx[i];
      if ((sy >= 0 && sy < h) && (sx >= 0 && sx < w) && mp[sy][sx] == inf) {
        mp[sy][sx] = mp[p.first][p.second] + 1;
        que.push(pair<int, int>(sy, sx));
      }
    }
  }
  int ma = -1;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ma = max(mp[i][j], ma);
    }
  }
  return ma;
}
int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    vs.push_back(s);
  }
  int ma = -100;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      ma = max(ma, bfs(pair<int, int>(i, j)));
    }
  }
  cout << ma << endl;
  return 0;
}
