#include <bits/stdc++.h>
using namespace std;
int fa[2][200005], to[2][200005], nxt[2][200005], hd[2][200005];
int dfn[2][200005], P[2][200005], siz[2][200005], num[2];
int trmn[200005 << 2], trsz[200005 << 2], trlz[200005 << 2], cnt[2];
char str[200005];
map<int, int> id[200005];
long long ans;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
inline void addedge(int u, int v, int op) {
  fa[op][u] = v, to[op][++cnt[op]] = u, nxt[op][cnt[op]] = hd[op][v],
  hd[op][v] = cnt[op];
}
inline void dfs(int u, int op) {
  dfn[op][u] = ++num[op], siz[op][u] = 1;
  for (int i = hd[op][u]; i; i = nxt[op][i]) {
    int v = to[op][i];
    dfs(v, op);
    siz[op][u] += siz[op][v];
  }
}
inline void pushup(int k) {
  if (trmn[k << 1] == trmn[k << 1 | 1])
    trmn[k] = trmn[k << 1], trsz[k] = trsz[k << 1] + trsz[k << 1 | 1];
  else if (trmn[k << 1] < trmn[k << 1 | 1])
    trmn[k] = trmn[k << 1], trsz[k] = trsz[k << 1];
  else
    trmn[k] = trmn[k << 1 | 1], trsz[k] = trsz[k << 1 | 1];
}
inline void pushdown(int k) {
  if (trlz[k]) {
    int tp = trlz[k];
    trlz[k] = 0;
    trlz[k << 1] += tp, trlz[k << 1 | 1] += tp;
    trmn[k << 1] += tp, trmn[k << 1 | 1] += tp;
  }
}
inline void build(int l, int r, int k) {
  trmn[k] = 0, trsz[k] = r - l + 1;
  if (l == r) return;
  int mid = l + r >> 1;
  build(l, mid, k << 1), build(mid + 1, r, k << 1 | 1);
}
inline void add(int x, int y, int z, int l, int r, int k) {
  if (x <= l && r <= y) {
    trmn[k] += z, trlz[k] += z;
    return;
  }
  pushdown(k);
  int mid = l + r >> 1;
  if (x <= mid) add(x, y, z, l, mid, k << 1);
  if (y > mid) add(x, y, z, mid + 1, r, k << 1 | 1);
  pushup(k);
}
inline void Dfs(int u) {
  add(dfn[1][u], dfn[1][u] + siz[1][u] - 1, 1, 1, num[1], 1);
  ans += (long long)(num[0] - ((trmn[1] == 0) ? trsz[1] : 0));
  for (int i = hd[0][u]; i; i = nxt[0][i]) Dfs(to[0][i]);
  add(dfn[1][u], dfn[1][u] + siz[1][u] - 1, -1, 1, num[1], 1);
}
int main() {
  int n = read(), m = read(), tot = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%s", str + 1);
    for (int j = 1; j <= m; j++) {
      if (str[j] == 'L') id[i][j] = id[i][j + 1] = ++tot;
      if (str[j] == 'U') id[i][j] = id[i + 1][j] = ++tot;
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (id[i][j] == id[i][j + 1]) {
        if ((i + j) & 1) {
          if (j + 2 <= m) addedge(id[i][j], id[i][j + 2], 1);
          if (j - 1 >= 1) addedge(id[i][j + 1], id[i][j - 1], 0);
        } else {
          if (j + 2 <= m) addedge(id[i][j], id[i][j + 2], 0);
          if (j - 1 >= 1) addedge(id[i][j + 1], id[i][j - 1], 1);
        }
      }
      if (id[i][j] == id[i + 1][j]) {
        if ((i + j) & 1) {
          if (i + 2 <= n) addedge(id[i][j], id[i + 2][j], 1);
          if (i - 1 >= 1) addedge(id[i + 1][j], id[i - 1][j], 0);
        } else {
          if (i + 2 <= n) addedge(id[i][j], id[i + 2][j], 0);
          if (i - 1 >= 1) addedge(id[i + 1][j], id[i - 1][j], 1);
        }
      }
    }
  for (int k = 0; k < 2; k++)
    for (int i = 1; i <= tot; i++)
      if (!fa[k][i]) dfs(i, k);
  build(1, num[1], 1);
  for (int i = 1; i <= tot; i++)
    if (!fa[0][i]) Dfs(i);
  printf("%lld\n", ans);
  return 0;
}
