#include <bits/stdc++.h>
const long long BIGMOD = 1e9 + 7;
using namespace std;
int h, w;
int** maze;
queue<vector<int>> que;
int wfs(int** map, int y, int x, int depth) {
  map[y][x] = 1;
  if (y - 1 >= 0 && map[y - 1][x] == 0)
    que.push(vector<int>{y - 1, x, depth + 1});
  if (y + 1 < h && map[y + 1][x] == 0)
    que.push(vector<int>{y + 1, x, depth + 1});
  if (x - 1 >= 0 && map[y][x - 1] == 0)
    que.push(vector<int>{y, x - 1, depth + 1});
  if (x + 1 < w && map[y][x + 1] == 0)
    que.push(vector<int>{y, x + 1, depth + 1});
  return depth;
}
int** copy(int** ngo) {
  int** ret = new int*[h];
  for (int i = 0; i < h; ++i) {
    ret[i] = new int[w];
    for (int j = 0; j < w; ++j) ret[i][j] = ngo[i][j];
  }
  return ret;
}
int main() {
  cin >> h >> w;
  maze = new int*[h];
  for (int i = 0; i < h; ++i) {
    maze[i] = new int[w];
    string str;
    cin >> str;
    for (int j = 0; j < w; ++j) {
      maze[i][j] = str[j] == '#' ? -1 : 0;
    }
  }
  int max = -1;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      int** mm = copy(maze);
      que.push(vector<int>{i, j, 0});
      while (que.size() > 0) {
        vector<int> q = que.front();
        que.pop();
        if (max < q[2]) max = q[2];
        wfs(mm, q[0], q[1], q[2]);
      }
    }
  }
  cout << max << endl;
}
