#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &num) {
  T x = 0, f = 1;
  char ch = getchar();
  for (; ch > '9' || ch < '0'; ch = getchar())
    if (ch == '-') f = -1;
  for (; ch <= '9' && ch >= '0'; ch = getchar())
    x = (x << 3) + (x << 1) + (ch ^ '0');
  num = x * f;
}
int n, m, X[400005], Y[400005], sf[400005], tot, cnt;
int head[400005], pre[400005 << 1], to[400005 << 1], in[400005], sz;
int st[400005], ed[400005], tme;
char s[400005];
long long ans;
inline int o(int i, int j) { return (i - 1) * m + j; }
inline void addedge(int u, int v) {
  pre[++sz] = head[u];
  head[u] = sz;
  to[sz] = v;
  ++in[v];
}
struct node {
  int x, l, r, v;
  bool operator<(const node b) const { return x != b.x ? x < b.x : v > b.v; }
} p[400005];
void dfs(int x) {
  st[x] = ++tme;
  for (int i = head[x]; i; i = pre[i]) {
    int y = to[i];
    dfs(y);
  }
  ed[x] = tme;
}
struct segtree {
  int sum[400005 << 2], tag[400005 << 2];
  inline void pushup(int ind, int l, int r) {
    if (tag[ind])
      sum[ind] = r - l + 1;
    else
      sum[ind] = sum[ind << 1] + sum[ind << 1 | 1];
  }
  void update(int ind, int l, int r, int x, int y, int v) {
    if (x <= l && r <= y) {
      tag[ind] += v;
      pushup(ind, l, r);
      return;
    }
    int mid = (l + r) >> 1;
    if (x <= mid) update(ind << 1, l, mid, x, y, v);
    if (mid < y) update(ind << 1 | 1, mid + 1, r, x, y, v);
    pushup(ind, l, r);
  }
} T;
int main() {
  read(n);
  read(m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    for (int j = 1; j <= m; j++) {
      if (s[j] == 'U') {
        X[++tot] = i;
        Y[tot] = j;
        sf[tot] = 0;
        if (i > 1) addedge(o(i - 1, j), o(i + 1, j));
        if (i < n - 1) addedge(o(i + 2, j), o(i, j));
      } else if (s[j] == 'L') {
        X[++tot] = i;
        Y[tot] = j;
        sf[tot] = 1;
        if (j > 1) addedge(o(i, j - 1), o(i, j + 1));
        if (j < m - 1) addedge(o(i, j + 2), o(i, j));
      }
    }
  }
  tme = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if ((i + j) % 2 == 0 && !in[o(i, j)]) dfs(o(i, j));
    }
  tme = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if ((i + j) % 2 == 1 && !in[o(i, j)]) dfs(o(i, j));
    }
  for (int i = 1; i <= tot; i++) {
    int a = 0, b = 0;
    if (!sf[i])
      a = o(X[i], Y[i]), b = o(X[i] + 1, Y[i]);
    else
      a = o(X[i], Y[i]), b = o(X[i], Y[i] + 1);
    if ((X[i] + Y[i]) % 2 == 0) {
      p[++cnt] = (node){st[a], st[b], ed[b], 1};
      p[++cnt] = (node){ed[a] + 1, st[b], ed[b], -1};
    } else {
      p[++cnt] = (node){st[b], st[a], ed[a], 1};
      p[++cnt] = (node){ed[b] + 1, st[a], ed[a], -1};
    }
  }
  sort(p + 1, p + cnt + 1);
  T.update(1, 1, n * m / 2, p[1].l, p[1].r, p[1].v);
  for (int i = 2; i <= cnt; i++) {
    ans += T.sum[1] * (p[i].x - p[i - 1].x);
    T.update(1, 1, n * m / 2, p[i].l, p[i].r, p[i].v);
  }
  printf("%lld\n", ans);
  return 0;
}
