#include <bits/stdc++.h>
using namespace std;
long long n, m, deg[200005];
string ch[200005];
vector<long long> edge[200005];
long long hhakioi(long long x, long long y) { return (x - 1) * m + y; }
void add(long long a, long long b, long long x) {
  if (a < 1 || a > n || b < 1 || b > m) return;
  edge[hhakioi(a, b)].push_back(x);
  deg[x]++;
}
long long cnt, siz[200005], dfn[200005], fa[200005];
void dfs(long long x) {
  siz[x] = 1;
  dfn[x] = ++cnt;
  for (long long i = 0; i < edge[x].size(); ++i) {
    long long v = edge[x][i];
    if (fa[x] == v) continue;
    fa[v] = x;
    dfs(v);
    siz[x] += siz[v];
  }
}
struct data {
  long long x, l, r, op;
  data(long long X = 0, long long L = 0, long long R = 0, long long O = 0) {
    x = X;
    l = L;
    r = R;
    op = O;
  }
  bool friend operator<(data a, data b) { return a.x < b.x; }
} Q[200005 << 1];
long long tot;
void ADD(long long a, long long b, long long c, long long d) {
  Q[++tot] = data(a, b, d, 1);
  Q[++tot] = data(c + 1, b, d, -1);
}
long long sum[200005 << 2], tag[200005 << 2];
void pushup(long long x, long long l, long long r) {
  if (tag[x])
    sum[x] = r - l + 1;
  else if (l != r)
    sum[x] = sum[(x << 1)] + sum[(x << 1 | 1)];
  else
    sum[x] = 0;
}
void change(long long x, long long l, long long r, long long b, long long e,
            long long v) {
  if (l > e || r < b) return;
  if (b <= l && r <= e) {
    tag[x] += v;
    pushup(x, l, r);
    return;
  }
  if (b <= ((l + r) >> 1)) change((x << 1), l, ((l + r) >> 1), b, e, v);
  if (e > ((l + r) >> 1)) change((x << 1 | 1), ((l + r) >> 1) + 1, r, b, e, v);
  pushup(x, l, r);
}
signed main() {
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= n; ++i) {
    cin >> ch[i];
    ch[i] = " " + ch[i];
    for (long long j = 1; j <= m; ++j) {
      if (ch[i][j] == 'L') add(i, j + 2, hhakioi(i, j));
      if (ch[i][j] == 'R') add(i, j - 2, hhakioi(i, j));
      if (ch[i][j] == 'U') add(i + 2, j, hhakioi(i, j));
      if (ch[i][j] == 'D') add(i - 2, j, hhakioi(i, j));
    }
  }
  for (long long i = 1; i <= n * m; ++i)
    if (!deg[i]) dfs(i);
  for (long long i = 1; i <= n; ++i)
    for (long long j = 1; j <= m; ++j) {
      if (ch[i][j] == 'L')
        ADD(dfn[hhakioi(i, j)], dfn[hhakioi(i, j + 1)],
            dfn[hhakioi(i, j)] + siz[hhakioi(i, j)] - 1,
            dfn[hhakioi(i, j + 1)] + siz[hhakioi(i, j + 1)] - 1);
      if (ch[i][j] == 'U')
        ADD(dfn[hhakioi(i, j)], dfn[hhakioi(i + 1, j)],
            dfn[hhakioi(i, j)] + siz[hhakioi(i, j)] - 1,
            dfn[hhakioi(i + 1, j)] + siz[hhakioi(i + 1, j)] - 1);
      if (ch[i][j] == 'R')
        ADD(dfn[hhakioi(i, j)], dfn[hhakioi(i, j - 1)],
            dfn[hhakioi(i, j)] + siz[hhakioi(i, j)] - 1,
            dfn[hhakioi(i, j - 1)] + siz[hhakioi(i, j - 1)] - 1);
      if (ch[i][j] == 'D')
        ADD(dfn[hhakioi(i, j)], dfn[hhakioi(i - 1, j)],
            dfn[hhakioi(i, j)] + siz[hhakioi(i, j)] - 1,
            dfn[hhakioi(i - 1, j)] + siz[hhakioi(i - 1, j)] - 1);
    }
  assert(tot <= n * m * 2);
  assert(cnt == n * m);
  sort(Q + 1, Q + 1 + tot);
  long long ans = 0;
  for (long long i = 1; i <= tot; ++i) {
    change(1, 1, cnt, Q[i].l, Q[i].r, Q[i].op);
    if (Q[i].x != Q[i + 1].x) ans = ans + 1ll * (Q[i + 1].x - Q[i].x) * sum[1];
  }
  printf("%lld\n", ans / 2);
  return 0;
}
