#include <bits/stdc++.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; }
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; }
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; }
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
}
typedef struct {
  int front;
  int rear;
  int data[100001][3];
} queue;
queue que;
void initQueue(queue *p) { p->front = p->rear = 0; }
bool emptyQueue(queue *p) { return p->front == p->rear; }
bool fullQueue(queue *p) {
  return (p->front - 1 == p->rear) || (p->front == 0 && p->rear == 100001 - 1);
}
void queuePop(queue *p) {
  if (emptyQueue(p)) {
    printf("UnderFlow\n");
    exit(1);
  } else {
    p->front++;
    if (p->front == 100001) p->front = 0;
  }
}
void queuePush(queue *p, int x, int y, int d) {
  if (fullQueue(p)) {
    printf("OverFlow\n");
    exit(1);
  } else {
    p->data[p->rear][0] = x;
    p->data[p->rear][1] = y;
    p->data[p->rear][2] = d;
    p->rear++;
    if (p->rear == 100001) p->rear = 0;
  }
}
int main(void) {
  char s[22][22];
  int h, w;
  scanf("%d %d", &h, &w);
  for (int hi = 0; hi < h; hi++) {
    scanf("%s", s[hi]);
  }
  int mx[4] = {0, 1, 0, -1};
  int my[4] = {1, 0, -1, 0};
  int ans = 0;
  for (int hi = 0; hi < h; hi++) {
    for (int wi = 0; wi < w; wi++) {
      if (s[hi][wi] == '#') continue;
      int visited[21][21] = {0};
      initQueue(&que);
      queuePush(&que, hi, wi, 0);
      while (!emptyQueue(&que)) {
        int x = que.data[que.front][0];
        int y = que.data[que.front][1];
        int d = que.data[que.front][2];
        queuePop(&que);
        visited[x][y] = 1;
        ans = (ans > d ? ans : d);
        for (int mi = 0; mi < 4; mi++) {
          int nextX = x + mx[mi];
          int nextY = y + my[mi];
          if (nextX < 0 || h <= nextX) continue;
          if (nextY < 0 || w <= nextY) continue;
          if (visited[nextX][nextY] == 1) continue;
          if (s[nextX][nextY] == '#') continue;
          queuePush(&que, nextX, nextY, d + 1);
        }
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
