#include <bits/stdc++.h>
template <typename T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  bool flag = false;
  while (!isdigit(c)) {
    if (c == '-') flag = true;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  if (flag) x = -x;
}
using namespace std;
int n, m;
inline int Id(int x, int y) { return (x - 1) * m + y; }
struct edge {
  int nxt, to;
  edge(int a = 0, int b = 0) { nxt = a, to = b; }
} e[201000 << 1];
int head[201000], ecnt;
int ind[201000];
inline void addedge(int from, int to) {
  e[++ecnt] = edge(head[from], to);
  head[from] = ecnt;
}
int dfn[201000], col[201000], dcnt[2], siz[201000];
void dfs(int cur, int t) {
  dfn[cur] = ++dcnt[t], col[cur] = t;
  siz[cur] = 1;
  for (int i = head[cur]; i; i = e[i].nxt) {
    int to = e[i].to;
    dfs(to, t);
    siz[cur] += siz[to];
  }
}
pair<int, int> jzp[201000];
int jtot;
struct operations {
  int t, p, d, u;
  operations(int aa = 0, int bb = 0, int cc = 0, int dd = 0) {
    t = aa, p = bb, d = cc, u = dd;
  }
} opt[201000 << 1];
int otot;
inline bool cmp(const operations &a, const operations &b) {
  return a.p < b.p || (a.p == b.p && a.t < b.t);
}
int ls[801000], rs[801000], root, ttot, sum[801000], tag[801000], len[801000];
void build(int L, int R, int &cur) {
  cur = ++ttot;
  len[cur] = R - L + 1;
  if (L == R) return;
  int mid = (L + R) >> 1;
  build(L, mid, ls[cur]), build(mid + 1, R, rs[cur]);
}
void modify(int L, int R, int l, int r, int x, int cur) {
  if (l <= L && R <= r) {
    tag[cur] += x;
    sum[cur] = tag[cur] ? len[cur] : sum[ls[cur]] + sum[rs[cur]];
    return;
  }
  int mid = (L + R) >> 1;
  if (l <= mid) modify(L, mid, l, r, x, ls[cur]);
  if (r > mid) modify(mid + 1, R, l, r, x, rs[cur]);
  sum[cur] = tag[cur] ? len[cur] : sum[ls[cur]] + sum[rs[cur]];
}
inline void work() {
  sort(opt + 1, opt + 1 + otot, cmp);
  build(1, dcnt[1], root);
  int ptr = 1;
  long long ans = 0;
  for (int i = 1; i <= dcnt[0]; ++i) {
    while (ptr <= otot && opt[ptr].p == i) {
      modify(1, dcnt[1], opt[ptr].d, opt[ptr].u, opt[ptr].t, root);
      ++ptr;
    }
    ans += sum[root];
  }
  printf("%lld\n", ans);
}
char s[201000];
int main() {
  read(n), read(m);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", s + 1);
    for (int j = 1; j <= m; ++j) {
      switch (s[j]) {
        case 'U': {
          if (i + 2 <= n) addedge(Id(i + 2, j), Id(i, j)), ++ind[Id(i, j)];
          jzp[++jtot] = make_pair(Id(i, j), Id(i + 1, j));
          break;
        }
        case 'D':
          if (i - 2 >= 1) addedge(Id(i - 2, j), Id(i, j)), ++ind[Id(i, j)];
          break;
        case 'L': {
          if (j + 2 <= m) addedge(Id(i, j + 2), Id(i, j)), ++ind[Id(i, j)];
          jzp[++jtot] = make_pair(Id(i, j), Id(i, j + 1));
          break;
        }
        case 'R':
          if (j - 2 >= 1) addedge(Id(i, j - 2), Id(i, j)), ++ind[Id(i, j)];
          break;
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= m; ++j) {
      int zzz = (i + j) & 1;
      if (!ind[Id(i, j)]) dfs(Id(i, j), zzz);
    }
  }
  for (int i = 1; i <= jtot; ++i) {
    int x = jzp[i].first, y = jzp[i].second;
    if (col[x]) swap(x, y);
    int l = dfn[x], faker = dfn[x] + siz[x];
    int d = dfn[y], u = dfn[y] + siz[y] - 1;
    opt[++otot] = operations(1, l, d, u);
    opt[++otot] = operations(-1, faker, d, u);
  }
  work();
  return 0;
}
