#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1, c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return f == 1 ? x : -x;
}
const int N = 2e5 + 4;
namespace seg {
int t[N << 2], lz[N << 2], len[N << 2];
inline void pushup(int p) {
  t[p] = lz[p] ? len[p] : (len[p] == 1 ? 0 : t[(p << 1)] + t[(p << 1 | 1)]);
}
void build(int p, int l, int r) {
  len[p] = r - l + 1;
  if (l == r) return;
  build((p << 1), l, ((l + r) >> 1));
  build((p << 1 | 1), ((l + r) >> 1) + 1, r);
}
void modify(int p, int l, int r, int ql, int qr, int v) {
  if (ql <= l && r <= qr) {
    lz[p] += v;
    pushup(p);
    return;
  }
  if (ql <= ((l + r) >> 1)) modify((p << 1), l, ((l + r) >> 1), ql, qr, v);
  if (((l + r) >> 1) < qr)
    modify((p << 1 | 1), ((l + r) >> 1) + 1, r, ql, qr, v);
  pushup(p);
}
}  // namespace seg
int n, m, C, tim, deg[N], st[N], ed[N];
char ss[N * 3], *s[N];
vector<int> e[N];
struct node {
  int l, r, w;
  node(int x, int y, int z) : l(x), r(y), w(z) {}
};
vector<node> vec[N];
inline void addedge(int u, int v) {
  deg[v]++;
  e[u].push_back(v);
}
inline int id(int x, int y) { return (x - 1) * m + y; }
void dfs(int x) {
  st[x] = ++tim;
  for (auto v : e[x]) dfs(v);
  ed[x] = tim;
}
long long ans;
int main() {
  n = read();
  m = read();
  s[0] = ss;
  for (int i = 1; i <= n; i++) {
    s[i] = s[i - 1] + m + 2;
    scanf("%s", s[i] + 1);
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (i > 1 && s[i - 1][j] == 'D') addedge(id(i, j), id(i - 2, j));
      if (j > 1 && s[i][j - 1] == 'R') addedge(id(i, j), id(i, j - 2));
      if (i < n && s[i + 1][j] == 'U') addedge(id(i, j), id(i + 2, j));
      if (j < m && s[i][j + 1] == 'L') addedge(id(i, j), id(i, j + 2));
    }
  C = n * m;
  for (int i = C; i; i--)
    if (!deg[i]) dfs(i);
  for (int i = 1, al, ar, bl, br; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (s[i][j] == 'L' || s[i][j] == 'U') {
        al = st[id(i, j)];
        ar = ed[id(i, j)];
        if (s[i][j] == 'L') {
          bl = st[id(i, j + 1)];
          br = ed[id(i, j + 1)];
        } else {
          bl = st[id(i + 1, j)];
          br = ed[id(i + 1, j)];
        }
        vec[al].push_back(node(bl, br, 1));
        vec[ar + 1].push_back(node(bl, br, -1));
        swap(al, bl);
        swap(ar, br);
        vec[al].push_back(node(bl, br, 1));
        vec[ar + 1].push_back(node(bl, br, -1));
      }
  seg::build(1, 1, C);
  for (int i = 1; i <= C; i++) {
    for (auto v : vec[i]) seg::modify(1, 1, C, v.l, v.r, v.w);
    ans += seg::t[1];
  }
  cout << ans / 2 << "\n";
  return (0 - 0);
}
