#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, m;
char s[1005][1005];
char ss[1005][1005];
int h[1005];
struct node {
  int r, c;
  node(int a, int b) : r(a), c(b) {}
};
vector<node> vec;
long long gao(char s[][1005], int n, int m);
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
  long long ans = 0;
  long long num = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == 'X') {
        vec.push_back(node(i, j));
        ans -= ((i - 1) * i / 2 + (n - i) * (long long)(n - i + 1) / 2) * m;
        ans -= ((j - 1) * j / 2 + (m - j) * (long long)(m - j + 1) / 2) * n;
        continue;
      }
      num++;
      ans += ((i - 1) * i / 2 + (n - i) * (long long)(n - i + 1) / 2) * m;
      ans += ((j - 1) * j / 2 + (m - j) * (long long)(m - j + 1) / 2) * n;
    }
  }
  int l, r;
  for (int i = 1; i <= n; i++) {
    l = 0, r = 0;
    bool flag = false;
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == 'X') {
        flag = true;
        continue;
      }
      if (!flag)
        l++;
      else
        r++;
    }
    ans += 2 * l * r * 2;
  }
  for (int i = 1; i <= m; i++) {
    l = 0, r = 0;
    bool flag = false;
    for (int j = 1; j <= n; j++) {
      if (s[j][i] == 'X') {
        flag = true;
        continue;
      }
      if (!flag)
        l++;
      else
        r++;
    }
    ans += 2 * 2 * l * r;
  }
  int len = vec.size();
  for (int i = 0; i < len; i++) {
    for (int j = 0; j < len; j++) {
      ans += abs(vec[i].r - vec[j].r) + abs(vec[i].c - vec[j].c);
    }
  }
  memset(h, -1, sizeof(h));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == 'X') {
        h[i] = j;
        break;
      }
    }
  }
  ans += gao(s, n, m);
  memset(h, -1, sizeof(h));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) ss[j][i] = s[i][j];
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++) {
      if (ss[i][j] == 'X') {
        h[i] = j;
        break;
      }
    }
  }
  ans += gao(ss, m, n);
  printf("%.10lf\n", ans * 1.0 / (num * num));
  return 0;
}
long long gao(char s[][1005], int n, int m) {
  long long res = 0;
  for (int i = 1; i <= n; i++) {
    if (h[i] != -1) {
      long long l = h[i] - 1;
      for (int j = i + 1; j <= n; j++) {
        if (h[j] == -1 || h[j] < h[j - 1]) break;
        res += l * (m - h[j]) * 2 * 2;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (h[i] != -1) {
      long long r = m - h[i];
      for (int j = i + 1; j <= n; j++) {
        if (h[j] == -1 || h[j] > h[j - 1]) break;
        res += r * (h[j] - 1) * 2 * 2;
      }
    }
  }
  return res;
}
