#include <bits/stdc++.h>
using namespace std;
const int maxn = 50005;
const double inf = 1e9;
int zou[4][2] = {-1, 0, 1, 0, 0, 1, 0, -1};
struct node {
  int x, y;
};
int v[25][25];
int w, h;
char c[25][25];
int judge(int x, int y) {
  if (c[x][y] == '#') return 0;
  if (x <= 0 || x > h || y <= 0 || y > w) return 0;
  return 1;
}
int bfs(int x, int y, node zd) {
  queue<node> que;
  node a;
  memset(v, -1, sizeof(v));
  a.x = x;
  a.y = y;
  v[x][y] = 0;
  que.push(a);
  int sum = 0;
  while (!que.empty()) {
    node n = que.front();
    cout << n.x << " " << n.y << endl;
    que.pop();
    if (n.x == zd.x && n.y == zd.y) return v[n.x][n.y];
    for (int i = 0; i < 4; i++) {
      if (v[n.x + zou[i][0]][n.y + zou[i][1]] == -1 &&
          judge(n.x + zou[i][0], n.y + zou[i][1])) {
        v[n.x + zou[i][0]][n.y + zou[i][1]] = v[n.x][n.y] + 1;
        node ls;
        ls.x = n.x + zou[i][0];
        ls.y = n.y + zou[i][1];
        que.push(ls);
      }
    }
  }
}
int main() {
  scanf("%d %d", &h, &w);
  for (int i = 1; i <= h; i++) {
    char ch;
    scanf("%c", &ch);
    for (int j = 1; j <= w; j++) scanf("%c", &c[i][j]);
  }
  node ls;
  ls.x = 2, ls.y = 3;
  bfs(1, 1, ls);
  int ma = 0;
  for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++) {
      if (judge(i, j)) {
        for (int ii = i; ii <= h; ii++)
          for (int jj = 1; jj <= w; jj++)
            if (judge(ii, jj)) {
              node ls;
              ls.x = ii, ls.y = jj;
              ma = max(ma, bfs(i, j, ls));
            }
      }
    }
  printf("%d\n", ma);
  return 0;
}
