#include <bits/stdc++.h>
using namespace std;
int N, M;
char c[1010][1010];
long long lux[1010][1010], luy[1010][1010], lus[1010][1010];
long long rux[1010][1010], ruy[1010][1010], rus[1010][1010];
long long ldx[1010][1010], ldy[1010][1010], lds[1010][1010];
long long rdx[1010][1010], rdy[1010][1010], rds[1010][1010];
long long hh[1010], ll[1010];
long long ans, s;
int main() {
  scanf("%d%d\n", &N, &M);
  for (long long i = 1; i <= N; i++) {
    for (long long j = 1; j <= M; j++) scanf("%c", &c[i][j]);
    scanf("\n");
  }
  for (long long i = 1; i <= N; i++)
    for (long long j = 1; j <= M; j++)
      if (c[i][j] == 'X') {
        hh[i] = j;
        ll[j] = i;
      }
  for (long long i = 1; i <= N; i++)
    for (long long j = 1; j <= M; j++) {
      lux[i][j] = lux[i][j - 1] + lux[i - 1][j] - lux[i - 1][j - 1];
      luy[i][j] = luy[i][j - 1] + luy[i - 1][j] - luy[i - 1][j - 1];
      lus[i][j] = lus[i][j - 1] + lus[i - 1][j] - lus[i - 1][j - 1];
      if (c[i][j] == '.') lux[i][j] += i, luy[i][j] += j, lus[i][j]++;
    }
  for (long long i = 1; i <= N; i++)
    for (long long j = M; j; j--) {
      rux[i][j] = rux[i][j + 1] + rux[i - 1][j] - rux[i - 1][j + 1];
      ruy[i][j] = ruy[i][j + 1] + ruy[i - 1][j] - ruy[i - 1][j + 1];
      rus[i][j] = rus[i][j + 1] + rus[i - 1][j] - rus[i - 1][j + 1];
      if (c[i][j] == '.') rux[i][j] += i, ruy[i][j] += j, rus[i][j]++;
    }
  for (long long i = N; i; i--)
    for (long long j = 1; j <= M; j++) {
      ldx[i][j] = ldx[i][j - 1] + ldx[i + 1][j] - ldx[i + 1][j - 1];
      ldy[i][j] = ldy[i][j - 1] + ldy[i + 1][j] - ldy[i + 1][j - 1];
      lds[i][j] = lds[i][j - 1] + lds[i + 1][j] - lds[i + 1][j - 1];
      if (c[i][j] == '.') ldx[i][j] += i, ldy[i][j] += j, lds[i][j]++;
    }
  for (long long i = N; i; i--)
    for (long long j = M; j; j--) {
      rdx[i][j] = rdx[i][j + 1] + rdx[i + 1][j] - rdx[i + 1][j + 1];
      rdy[i][j] = rdy[i][j + 1] + rdy[i + 1][j] - rdy[i + 1][j + 1];
      rds[i][j] = rds[i][j + 1] + rds[i + 1][j] - rds[i + 1][j + 1];
      if (c[i][j] == '.') rdx[i][j] += i, rdy[i][j] += j, rds[i][j]++;
    }
  ans = 0;
  for (long long i = 1; i <= N; i++)
    for (long long j = 1; j <= M; j++)
      if (c[i][j] != 'X') {
        ans += abs(i * lus[i - 1][j - 1] - lux[i - 1][j - 1]) +
               abs(j * lus[i - 1][j - 1] - luy[i - 1][j - 1]);
        ans += abs(i * rus[i - 1][j + 1] - rux[i - 1][j + 1]) +
               abs(j * rus[i - 1][j + 1] - ruy[i - 1][j + 1]);
        ans += abs(i * lds[i + 1][j - 1] - ldx[i + 1][j - 1]) +
               abs(j * lds[i + 1][j - 1] - ldy[i + 1][j - 1]);
        ans += abs(i * rds[i + 1][j + 1] - rdx[i + 1][j + 1]) +
               abs(j * rds[i + 1][j + 1] - rdy[i + 1][j + 1]);
        if (hh[i]) {
          if (hh[i] > j) {
            ans += (j - 1) * j / 2;
            ans += (hh[i] - j - 1) * (hh[i] - j) / 2;
            ans += (M - hh[i]) * (M - j + 2 + hh[i] + 1 - j + 2) / 2;
          } else {
            ans += (M - j) * (M - j + 1) / 2;
            ans += (j - hh[i] - 1) * (j - hh[i]) / 2;
            ans += (hh[i] - 1) * (j - 1 + 2 + j - (hh[i] - 1) + 2) / 2;
          }
        } else {
          ans += (j - 1) * j / 2;
          ans += (M - j) * (M - j + 1) / 2;
        }
        if (ll[j]) {
          if (ll[j] > i) {
            ans += (i - 1) * i / 2;
            ans += (ll[j] - i - 1) * (ll[j] - i) / 2;
            ans += (N - ll[j]) * (N - i + 2 + ll[j] + 1 - i + 2) / 2;
          } else {
            ans += (N - i) * (N - i + 1) / 2;
            ans += (i - ll[j] - 1) * (i - ll[j]) / 2;
            ans += (ll[j] - 1) * (i - 1 + 2 + i - (ll[j] - 1) + 2) / 2;
          }
        } else {
          ans += (i - 1) * i / 2;
          ans += (N - i) * (N - i + 1) / 2;
        }
      }
  for (int i = 1; i < N; i++) {
    int j = i;
    while (hh[j] && hh[j + 1] && (hh[j + 1] > hh[j])) j++;
    for (int x = i; x < j; x++)
      for (int y = x + 1; y <= j; y++) {
        if (hh[x] < hh[y])
          ans += 4 * (hh[x] - 1) * (M - hh[y]);
        else
          ans += 4 * (hh[y] - 1) * (M - hh[x]);
      }
    i = j;
  }
  for (int i = 1; i < N; i++) {
    int j = i;
    while (hh[j] && hh[j + 1] && (hh[j + 1] < hh[j])) j++;
    for (int x = i; x < j; x++)
      for (int y = x + 1; y <= j; y++) {
        if (hh[x] < hh[y])
          ans += 4 * (hh[x] - 1) * (M - hh[y]);
        else
          ans += 4 * (hh[y] - 1) * (M - hh[x]);
      }
    i = j;
  }
  for (int i = 1; i < M; i++) {
    int j = i;
    while (ll[j] && ll[j + 1] && (ll[j + 1] > ll[j])) j++;
    for (int x = i; x < j; x++)
      for (int y = x + 1; y <= j; y++) {
        if (ll[x] < ll[y])
          ans += 4 * (ll[x] - 1) * (N - ll[y]);
        else
          ans += 4 * (ll[y] - 1) * (N - ll[x]);
      }
    i = j;
  }
  for (int i = 1; i < M; i++) {
    int j = i;
    while (ll[j] && ll[j + 1] && (ll[j + 1] < ll[j])) j++;
    for (int x = i; x < j; x++)
      for (int y = x + 1; y <= j; y++) {
        if (ll[x] < ll[y])
          ans += 4 * (ll[x] - 1) * (N - ll[y]);
        else
          ans += 4 * (ll[y] - 1) * (N - ll[x]);
      }
    i = j;
  }
  for (long long i = 1; i <= N; i++)
    for (long long j = 1; j <= M; j++)
      if (c[i][j] == '.')
        s += lus[i][j] + rus[i][j + 1] + lds[i + 1][j] + rds[i + 1][j + 1];
  printf("%0.8lf", double(ans) / double(s));
}
