#include <bits/stdc++.h>
using namespace std;
const int MAX = 1200;
long long row[MAX], col[MAX];
long long sol1[MAX][MAX];
long long soltt[MAX];
long long sol2[MAX];
long long n, m;
char mm[MAX][MAX];
int main() {
  scanf("%lld %lld", &n, &m);
  long long cnt = 0;
  for (int i = 0; i < n; i++) scanf("%s", mm[i]);
  for (int j = 1; j <= m; j++) col[j] = -1;
  for (int i = 0; i < n; i++) {
    row[i + 1] = -1;
    for (int j = 0; j < m; j++) {
      if (mm[i][j] == 'X') row[i + 1] = j + 1, col[j + 1] = i + 1, cnt++;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      sol1[i][j] = (j * (j - 1)) / 2 + (m - j + 1) * (m - j) / 2;
      if (row[i] != -1) sol1[i][j] -= std::abs(j - row[i]);
    }
  }
  long long t1, t2, t3, t4, dir;
  for (int i = 1; i <= n; i++) {
    t1 = 0;
    for (int j = 1; j <= m; j++) {
      if (j != row[i]) t1 += sol1[i][j];
    }
    t2 = 0;
    if (i != 1) {
      for (int j = 1; j <= m; j++) {
        if (j != row[i]) {
          t2 += soltt[j];
        }
      }
    }
    t2 <<= 1;
    t4 = 0;
    for (int j = i - 1; j >= 1; j--) {
      if (row[j] == -1)
        t4 += (i - j) * m;
      else
        t4 += (i - j) * (m - 1);
    }
    if (row[i] == -1)
      t4 = t4 * m;
    else
      t4 = t4 * (m - 1);
    t4 <<= 1;
    if (i == 1)
      sol2[i] = t1 + t2 + t4;
    else
      sol2[i] = sol2[i - 1] + t1 + t2 + t4;
    if (i == 1)
      for (int j = 1; j <= m; j++) soltt[j] = sol1[1][j];
    else
      for (int j = 1; j <= m; j++) soltt[j] += sol1[i][j];
  }
  for (int i = 1; i <= n; i++) {
    t3 = 0;
    if (row[i] == -1)
      dir = 0;
    else if (i - 1 < 1 || row[i - 1] == -1)
      dir = 3;
    else if (row[i - 1] > row[i]) {
      dir = 2;
      long long r = i - 2;
      t3 = 2 * m - row[i] - row[i - 1];
      while (r >= 1 && row[r] != -1 && row[r] > row[r + 1])
        t3 += m - row[r], r--;
    } else if (row[i - 1] < row[i]) {
      dir = 1;
      long long r = i - 2;
      t3 = row[i] + row[i - 1] - 2;
      while (r >= 1 && row[r] != -1 && row[r] < row[r + 1])
        t3 += row[r] - 1, r--;
    }
    if (dir == 3) t3 = (row[i] - 1) * (m - row[i]) * 4;
    if (dir == 2) t3 = t3 * (row[i] - 1) * 4;
    if (dir == 1) t3 = t3 * (m - row[i]) * 4;
    if (t3) {
      sol2[n] += t3;
    }
  }
  for (int i = 1; i <= m; i++) {
    t3 = 0;
    if (col[i] == -1)
      dir = 0;
    else if (i - 1 < 1 || col[i - 1] == -1)
      dir = 3;
    else if (col[i - 1] > col[i]) {
      dir = 2;
      long long r = i - 2;
      t3 = 2 * n - col[i] - col[i - 1];
      while (r >= 1 && col[r] != -1 && col[r] > col[r + 1])
        t3 += n - col[r], r--;
    } else if (col[i - 1] < col[i]) {
      dir = 1;
      long long r = i - 2;
      t3 = col[i] + col[i - 1] - 2;
      while (r >= 1 && col[r] != -1 && col[r] < col[r + 1])
        t3 += col[r] - 1, r--;
    }
    if (dir == 3) t3 = (col[i] - 1) * (n - col[i]) * 4;
    if (dir == 2) t3 = t3 * (col[i] - 1) * 4;
    if (dir == 1) t3 = t3 * (n - col[i]) * 4;
    if (t3) {
      sol2[n] += t3;
    }
  }
  cnt = n * m - cnt;
  long long tempcnt = cnt;
  cnt = cnt * (cnt - 1);
  printf("%.12lf\n", (double)sol2[n] / (cnt + tempcnt));
  return 0;
}
