#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000009;
char maze[25][25];
void solve() {
  int h, w;
  cin >> h >> w;
  for (long long i = 0; i < w + 2; i++) {
    maze[0][i] = '#';
  }
  for (long long i = 0; i < w + 2; i++) {
    maze[h + 1][i] = '#';
  }
  for (long long i = 0; i < h + 2; i++) {
    maze[i][0] = '#';
  }
  for (long long i = 0; i < h + 2; i++) {
    maze[i][w + 1] = '#';
  }
  for (long long i = 0; i < h; i++) {
    for (long long j = 0; j < w; j++) {
      cin >> maze[i + 1][j + 1];
    }
  }
  for (long long i = 0; i < h + 2; i++) {
    for (long long j = 0; j < w + 2; j++) {
    }
  }
  int score = 0;
  for (long long i = 0; i < h + 2; i++) {
    for (long long j = 0; j < w + 2; j++) {
      if (maze[i][j] == '.') {
        queue<pair<int, int>> q;
        int dis[22][22];
        for (long long p = 0; p < 22; p++) {
          for (long long q = 0; q < 22; q++) {
            dis[p][q] = -1;
          }
        }
        bool visit[22][22];
        for (long long p = 0; p < 22; p++) {
          for (long long q = 0; q < 22; q++) {
            visit[p][q] = false;
          }
        }
        q.push(make_pair(i, j));
        while (!q.empty()) {
          auto p = q.front();
          q.pop();
          auto x = p.first;
          auto y = p.second;
          if (maze[x + 1][y] == '.' && visit[x + 1][y] == false) {
            dis[x + 1][y] = dis[x][y] + 1;
            q.push(make_pair(x + 1, y));
            visit[x + 1][y] = true;
          }
          if (maze[x - 1][y] == '.' && visit[x - 1][y] == false) {
            dis[x - 1][y] = dis[x][y] + 1;
            q.push(make_pair(x - 1, y));
            visit[x - 1][y] = true;
          }
          if (maze[x][y + 1] == '.' && visit[x][y + 1] == false) {
            dis[x][y + 1] = dis[x][y] + 1;
            q.push(make_pair(x, y + 1));
            visit[x][y + 1] = true;
          }
          if (maze[x][y - 1] == '.' && visit[x][y - 1] == false) {
            dis[x][y - 1] = dis[x][y] + 1;
            q.push(make_pair(x, y - 1));
            visit[x][y - 1] = true;
          }
        }
        for (long long i = 0; i < h + 2; i++) {
          for (long long j = 0; j < w + 2; j++) {
            score = max(score, dis[i][j]);
          }
        }
      }
    }
  }
  cout << score + 1 << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
