#include <bits/stdc++.h>
using namespace std;
int solve(int sw, int sh, int gw, int gh) {}
int main() {
  int H, W;
  cin >> H >> W;
  char S[H][W];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S[i][j];
    }
  }
  int m = 0;
  for (int sw = 0; sw < W; sw++) {
    for (int sh = 0; sh < H; sh++) {
      for (int gw = 0; gw < W; gw++) {
        for (int gh = 0; gh < H; gh++) {
          if (sw == gw && sh == gh) continue;
          if (S[sh][sw] == '#' || S[gh][gw] == '#') continue;
          queue<pair<int, int>> q;
          q.push(make_pair(sh, sw));
          int fl[H][W];
          for (int i = 0; i < W; i++) {
            for (int j = 0; j < H; j++) {
              fl[j][i] = -1;
            }
          }
          fl[sh][sw] = 0;
          while (!q.empty()) {
            int y = q.front().first;
            int x = q.front().second;
            if (x == gw && y == gh) break;
            if (y + 1 < H && S[y + 1][x] == '.' && fl[y + 1][x] == -1) {
              q.push(make_pair(y + 1, x));
              fl[y + 1][x] = fl[y][x] + 1;
            }
            if (y - 1 >= 0 && S[y - 1][x] == '.' && fl[y - 1][x] == -1) {
              q.push(make_pair(y - 1, x));
              fl[y - 1][x] = fl[y][x] + 1;
            }
            if (x + 1 < W && S[y][x + 1] == '.' && fl[y][x + 1] == -1) {
              q.push(make_pair(y, x + 1));
              fl[y][x + 1] = fl[y][x] + 1;
            }
            if (x - 1 >= 0 && S[y][x - 1] == '.' && fl[y][x - 1] == -1) {
              q.push(make_pair(y, x - 1));
              fl[y][x - 1] = fl[y][x] + 1;
            }
            q.pop();
          }
          if (sw == 0 && sh == 2 && gw == 4 && gh == 0)
            cout << fl[gh][gw] << endl;
          m = max(m, fl[gh][gw]);
        }
      }
    }
  }
  cout << m;
  return 0;
}
