#include <bits/stdc++.h>
using namespace std;
char s[200010];
int n, m, head[200010], o = 0, x[2], id[200010], sz[200010], cnt = 0,
                        tree[800010], tag[800010];
bool isnt_rt[200010];
vector<vector<int> > w;
struct edge {
  int to, link;
} e[200010];
struct seg {
  int x, l, r, id;
  bool operator<(const seg &b) const { return x < b.x; }
} sg[200010];
void add_edge(int u, int v) {
  e[++o].to = v, e[o].link = head[u], head[u] = o, isnt_rt[v] = true;
}
void dfs(int u, int k) {
  id[u] = ++x[k], sz[u] = 1;
  for (int i = head[u]; i; i = e[i].link) {
    dfs(e[i].to, k);
    sz[u] += sz[e[i].to];
  }
}
void pushup(int l, int r, int t) {
  if (tag[t] > 0) return tree[t] = (r - l + 1), void();
  if (l == r) return tree[t] = 0, void();
  tree[t] = tree[t << 1] + tree[t << 1 | 1];
}
void add(int ll, int rr, int l, int r, int t, int c) {
  if (ll <= l && r <= rr) {
    tag[t] += c;
    pushup(l, r, t);
    return;
  }
  int mid = (l + r) >> 1;
  if (ll <= mid) add(ll, rr, l, mid, t << 1, c);
  if (mid < rr) add(ll, rr, mid + 1, r, t << 1 | 1, c);
  pushup(l, r, t);
}
int main() {
  scanf("%d%d", &n, &m), w.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    w[i].resize(m + 1);
    scanf("%s", s + 1);
    for (int j = 1; j <= m; j++) {
      if (s[j] == 'L') w[i][j] = 1;
      if (s[j] == 'U') w[i][j] = 2;
      if (s[j] == 'L' && j + 2 <= m)
        add_edge(((i)-1) * m + (j + 2), ((i)-1) * m + (j));
      if (s[j] == 'R' && j - 2 >= 1)
        add_edge(((i)-1) * m + (j - 2), ((i)-1) * m + (j));
      if (s[j] == 'U' && i + 2 <= n)
        add_edge(((i + 2) - 1) * m + (j), ((i)-1) * m + (j));
      if (s[j] == 'D' && i - 2 >= 1)
        add_edge(((i - 2) - 1) * m + (j), ((i)-1) * m + (j));
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (isnt_rt[((i)-1) * m + (j)]) continue;
      dfs(((i)-1) * m + (j), (i + j) & 1);
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int u, v;
      if (w[i][j] == 1) {
        u = ((i)-1) * m + (j), v = ((i)-1) * m + (j + 1);
        if ((i + j) & 1) swap(u, v);
      } else if (w[i][j] == 2) {
        u = ((i)-1) * m + (j), v = ((i + 1) - 1) * m + (j);
        if ((i + j) & 1) swap(u, v);
      } else
        continue;
      sg[++cnt] = (seg){id[u], id[v], id[v] + sz[v] - 1, 1};
      sg[++cnt] = (seg){id[u] + sz[u], id[v], id[v] + sz[v] - 1, -1};
    }
  sort(sg + 1, sg + cnt + 1);
  long long ans = 0;
  for (int i = 1, j = 1; i <= x[0]; i++) {
    while (sg[j].x <= i && j <= cnt) {
      add(sg[j].l, sg[j].r, 1, x[1], 1, sg[j].id);
      j++;
    }
    ans += tree[1];
  }
  printf("%lld\n", ans);
}
