#include <bits/stdc++.h>
const int maxn = 6e5 + 7;
int n, m, vis[maxn], tl, notrt[maxn], dfn[maxn], idx, size[maxn], LM;
std::vector<std::pair<int, int> > P[maxn];
char s[maxn];
long long ans = 0;
std::vector<char> G[maxn];
std::vector<int> ch[maxn];
int hash(int i, int j) { return (i - 1) * m + j; }
void link(int i, int j, int k, int l) {
  ch[hash(i, j)].push_back(hash(k, l));
  notrt[hash(k, l)] = 1;
}
void dfs(int u) {
  size[u] = 1;
  dfn[u] = ++idx;
  for (int v : ch[u]) {
    dfs(v);
    size[u] += size[v];
  }
}
struct data {
  int cnt, min;
};
data NULLDAT() {
  data d;
  d.min = 1e9;
  d.cnt = 0;
  return d;
}
data merge(data a, data b) {
  data c;
  if (a.min < b.min) {
    c.cnt = a.cnt;
  } else if (a.min > b.min) {
    c.cnt = b.cnt;
  } else
    c.cnt = a.cnt + b.cnt;
  c.min = std::min(a.min, b.min);
  return c;
}
struct Asriel_Loves_Chara {
  data sum[maxn << 2];
  int tag[maxn << 2];
  void give_tag(int x, int v) {
    tag[x] += v;
    sum[x].min += v;
  }
  void pushdown(int x) {
    tag[x << 1] += tag[x];
    sum[x << 1].min += tag[x];
    tag[x << 1 | 1] += tag[x];
    sum[x << 1 | 1].min += tag[x];
    tag[x] = 0;
  }
  void update(int x) { sum[x] = merge(sum[x << 1], sum[x << 1 | 1]); }
  void build(int l, int r, int rt) {
    if (l == r) {
      sum[rt].cnt = 1;
      sum[rt].min = 0;
      return;
    }
    build(l, (l + r) >> 1, rt << 1);
    build(((l + r) >> 1) + 1, r, rt << 1 | 1);
    update(rt);
  }
  void add(int l, int r, int L, int R, int v, int rt) {
    if (l > R || r < L) return;
    if (l <= L && R <= r) {
      give_tag(rt, v);
      return;
    }
    pushdown(rt);
    add(l, r, L, (L + R) >> 1, v, rt << 1);
    add(l, r, ((L + R) >> 1) + 1, R, v, rt << 1 | 1);
    update(rt);
  }
} sgt;
namespace scanner {
int cnt = 0;
struct event {
  int p, l, r, d;
} arr[maxn << 1];
event New(int p, int l, int r, int d) {
  event E;
  E.p = p;
  E.l = l;
  E.r = r;
  E.d = d;
  return E;
}
int cmp(event a, event b) { return a.p < b.p; }
void add(int l1, int r1, int l2, int r2) {
  arr[++cnt] = New(l1, l2, r2, 1);
  arr[++cnt] = New(r1 + 1, l2, r2, -1);
}
void work() {
  sgt.build(1, LM, 1);
  std::sort(arr + 1, arr + cnt + 1, cmp);
  int p = 0;
  for (int i = 1; i <= LM; ++i) {
    while (p < cnt && arr[p + 1].p <= i) {
      p++;
      sgt.add(arr[p].l, arr[p].r, 1, LM, arr[p].d, 1);
    }
    int zero = 0;
    data d = sgt.sum[1];
    if (d.min > 0)
      zero = 0;
    else
      zero = d.cnt;
    ans += LM - zero;
  }
}
}  // namespace scanner
int main() {
  scanf("%d%d", &n, &m);
  LM = n * m;
  for (int i = 0; i <= n + 1; ++i) G[i].resize(m + 3);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", s + 1);
    for (int j = 1; j <= m; ++j) G[i][j] = s[j];
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      if (G[i + 1][j] == 'U' && i + 2 <= n && G[i + 2][j] == 'D')
        link(i, j, i + 2, j);
      if (G[i - 1][j] == 'D' && i - 2 >= 1 && G[i - 2][j] == 'U')
        link(i, j, i - 2, j);
      if (G[i][j + 1] == 'L' && j + 2 <= m && G[i][j + 2] == 'R')
        link(i, j, i, j + 2);
      if (G[i][j - 1] == 'R' && j - 2 >= 1 && G[i][j - 2] == 'L')
        link(i, j, i, j - 2);
      if (!vis[hash(i, j)]) {
        vis[hash(i, j)] = ++tl;
        if (G[i][j] == 'L') vis[hash(i, j + 1)] = tl;
        if (G[i][j] == 'U') vis[hash(i + 1, j)] = tl;
      }
      P[vis[hash(i, j)]].push_back(std::make_pair(i, j));
    }
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      if (!notrt[hash(i, j)]) {
        assert(!dfn[hash(i, j)]);
        dfs(hash(i, j));
      }
  for (int i = 1; i <= tl; ++i) {
    int x1 = P[i][0].first, y1 = P[i][0].second, x2 = P[i][1].first,
        y2 = P[i][1].second;
    int u = hash(x1, y1), v = hash(x2, y2);
    int l1 = dfn[u], r1 = dfn[u] + size[u] - 1;
    int l2 = dfn[v], r2 = dfn[v] + size[v] - 1;
    if ((x1 + y1) & 1) {
      std::swap(l1, l2);
      std::swap(r1, r2);
    }
    scanner::add(l1, r1, l2, r2);
  }
  scanner::work();
  printf("%lld", ans);
  return 0;
}
