#include <bits/stdc++.h>
using namespace std;
int d[20][20] = {};
int H, W;
char OK = '.', NG = '#';
pair<int, int> s_p, e_p;
void display_vec(vector<string> v) {
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << endl;
  }
  cout << endl;
}
void display_dis() {
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cout << d[i][j] << ' ';
    }
    cout << endl;
  }
  cout << endl;
}
void init_dis() {
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      d[i][j] = -1;
    }
  }
}
int bfs(vector<string> v) {
  int dx[4] = {0, 0, 1, -1};
  int dy[4] = {1, -1, 0, 0};
  queue<pair<int, int>> q;
  init_dis();
  pair<int, int> cur_p, next_p;
  q.push(s_p);
  d[s_p.second][s_p.first] = 0;
  int max_dis = -1;
  while (q.size()) {
    cur_p = q.front();
    v[cur_p.second][cur_p.first] = NG;
    q.pop();
    for (int i = 0; i < 4; i++) {
      next_p.second = cur_p.second + dy[i];
      next_p.first = cur_p.first + dx[i];
      if (next_p.second >= 0 && next_p.second < H && next_p.first >= 0 &&
          next_p.first < W) {
        if (v[next_p.second][next_p.first] == OK &&
            d[next_p.second][next_p.first] == -1) {
          d[next_p.second][next_p.first] = d[cur_p.second][cur_p.first] + 1;
          q.push(next_p);
          if (d[next_p.second][next_p.first] > max_dis) {
            max_dis = d[next_p.second][next_p.first];
          }
        }
      }
    }
  }
  return max_dis;
}
int main(int argc, const char *argv[]) {
  cin >> H >> W;
  vector<string> v;
  string s;
  for (int i = 0; i < H; i++) {
    cin >> s;
    v.push_back(s);
  }
  int x, ans = -1;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      s_p.second = i;
      s_p.first = j;
      x = bfs(v);
      if (x > ans) {
        ans = x;
      }
    }
  }
  cout << ans << endl;
}
