#include <bits/stdc++.h>
void Get(int &T) {
  char C;
  bool F = 0;
  for (; C = getchar(), C < '0' || C > '9';)
    if (C == '-') F = 1;
  for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0')
    ;
  F && (T = -T);
}
char S[1005][1005];
int N, M;
void Init() {
  Get(N);
  Get(M);
  for (int i = 1; i <= N; i++) gets(S[i] + 1);
}
int PosX[1005];
int PosY[1005];
long long Ans;
double Ans2;
void Work() {
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= M; j++)
      if (S[i][j] == 'X') {
        PosY[i] = j;
        PosX[j] = i;
      }
  int Last = 0;
  long long Cnt = 0;
  for (int i = 1; i <= N; i++) {
    if (PosY[i] > 0) {
      if (PosY[i] > Last) {
        Last = PosY[i];
        Cnt += PosY[i] - 1;
      } else {
        Last = PosY[i];
        Cnt = PosY[i] - 1;
      }
      Ans += ((long long)(M - PosY[i]) * (long long)(Cnt) << 1);
    } else
      Last = Cnt = 0;
  }
  Last = Cnt = 0;
  for (int i = N; i >= 1; i--) {
    if (PosY[i] > 0) {
      if (PosY[i] > Last) {
        Ans += ((long long)(M - PosY[i]) * (long long)(Cnt) << 1);
        Last = PosY[i];
        Cnt += PosY[i] - 1;
      } else {
        Last = PosY[i];
        Cnt = PosY[i] - 1;
      }
    } else
      Last = Cnt = 0;
  }
  Last = 0x2f2f2f2f;
  Cnt = 0;
  for (int i = 1; i <= N; i++) {
    if (PosY[i] > 0) {
      if (PosY[i] < Last) {
        Last = PosY[i];
        Cnt += M - PosY[i];
      } else {
        Last = PosY[i];
        Cnt = M - PosY[i];
      }
      Ans += ((long long)(PosY[i] - 1) * (long long)(Cnt) << 1);
    } else {
      Last = 0x2f2f2f2f;
      Cnt = 0;
    }
  }
  Last = 0x2f2f2f2f;
  Cnt = 0;
  for (int i = N; i >= 1; i--) {
    if (PosY[i] > 0) {
      if (PosY[i] < Last) {
        Ans += ((long long)(PosY[i] - 1) * (long long)(Cnt) << 1);
        Last = PosY[i];
        Cnt += M - PosY[i];
      } else {
        Last = PosY[i];
        Cnt = M - PosY[i];
      }
    } else {
      Last = 0x2f2f2f2f;
      Cnt = 0;
    }
  }
  Last = Cnt = 0;
  for (int i = 1; i <= M; i++) {
    if (PosX[i] > 0) {
      if (PosX[i] > Last) {
        Last = PosX[i];
        Cnt += PosX[i] - 1;
      } else {
        Last = PosX[i];
        Cnt = PosX[i] - 1;
      }
      Ans += ((long long)(N - PosX[i]) * (long long)(Cnt) << 1);
    } else
      Last = Cnt = 0;
  }
  Last = Cnt = 0;
  for (int i = M; i >= 1; i--) {
    if (PosX[i] > 0) {
      if (PosX[i] > Last) {
        Ans += ((long long)(N - PosX[i]) * (long long)(Cnt) << 1);
        Last = PosX[i];
        Cnt += PosX[i] - 1;
      } else {
        Last = PosX[i];
        Cnt = PosX[i] - 1;
      }
    } else
      Last = Cnt = 0;
  }
  Last = 0x2f2f2f2f;
  Cnt = 0;
  for (int i = 1; i <= M; i++) {
    if (PosX[i] > 0) {
      if (PosX[i] < Last) {
        Last = PosX[i];
        Cnt += N - PosX[i];
      } else {
        Last = PosX[i];
        Cnt = N - PosX[i];
      }
      Ans += ((long long)(PosX[i] - 1) * (long long)(Cnt) << 1);
    } else {
      Last = 0x2f2f2f2f;
      Cnt = 0;
    }
  }
  Last = 0x2f2f2f2f;
  Cnt = 0;
  for (int i = M; i >= 1; i--) {
    if (PosX[i] > 0) {
      if (PosX[i] < Last) {
        Ans += ((long long)(PosX[i] - 1) * (long long)(Cnt) << 1);
        Last = PosX[i];
        Cnt += N - PosX[i];
      } else {
        Last = PosX[i];
        Cnt = N - PosX[i];
      }
    } else {
      Last = 0x2f2f2f2f;
      Cnt = 0;
    }
  }
  Ans += ((long long)M * (long long)M * (long long)(N - 1) * (long long)N *
          (long long)(N + 1)) /
         3;
  Ans += ((long long)N * (long long)N * (long long)(M - 1) * (long long)M *
          (long long)(M + 1)) /
         3;
  for (int i = 1; i <= N; i++) {
    if (PosY[i] > 0) {
      Ans -= (((long long)PosY[i] * (long long)(PosY[i] - 1) * (long long)N));
      Ans -= ((long long)(M - PosY[i]) * (long long)(M - PosY[i] + 1) *
              (long long)N);
      Ans -= ((long long)i * (long long)(i - 1) * (long long)M);
      Ans -= ((long long)(N - i) * (long long)(N - i + 1) * (long long)M);
    }
  }
  Cnt = 0;
  int Cnt_0 = 0;
  for (int i = 1; i <= N; i++)
    if (PosY[i] > 0) {
      Ans += (((long long)i * (long long)Cnt_0 - Cnt) << 1);
      Cnt_0++;
      Cnt += i;
    }
  Cnt = 0;
  Cnt_0 = 0;
  for (int i = 1; i <= M; i++)
    if (PosX[i] > 0) {
      Ans += (((long long)i * (long long)Cnt_0 - Cnt) << 1);
      Cnt_0++;
      Cnt += i;
    }
  double Sum = N * M;
  for (int i = 1; i <= N; i++)
    if (PosY[i] > 0) Sum -= 1;
  Ans2 = Ans / (double)(Sum * Sum);
}
void Output() { printf("%.9lf\n", Ans2); }
int main() {
  Init();
  Work();
  Output();
  return 0;
}
