#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
using LL = long long;
template <typename T>
inline void chkmin(T& a, const T& b) {
  a = a < b ? a : b;
}
template <typename T>
inline void chkmax(T& a, const T& b) {
  a = a > b ? a : b;
}
const int MAXN = 200005, MAXT = 1 << 19;
char *mp[MAXN], mem[MAXN];
int beg[MAXN], ed[MAXN], sum[MAXT], tag[MAXT], n, m, tot;
vector<int> edge[MAXN];
struct Opt {
  int l, r, tp;
};
vector<Opt> md[MAXN];
inline void dfs(int u) {
  assert(!beg[u]);
  beg[u] = ++tot;
  for (int v : edge[u]) dfs(v);
  ed[u] = tot;
}
inline void modify(int a, int b, int t, int l = 1, int r = tot, int k = 1) {
  if (a > r || b < l) return;
  if (a <= l && b >= r) {
    tag[k] += t;
    sum[k] = tag[k] ? r - l + 1 : (l == r ? 0 : sum[k << 1] + sum[k << 1 | 1]);
    return;
  }
  int mid = (l + r) >> 1;
  modify(a, b, t, l, mid, k << 1);
  modify(a, b, t, mid + 1, r, k << 1 | 1);
  sum[k] = tag[k] ? r - l + 1 : sum[k << 1] + sum[k << 1 | 1];
}
int main() {
  n = read();
  m = read();
  for (int i = 0; i < n; i++) {
    mp[i] = mem + i * m;
    scanf("%s", mp[i]);
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) {
      char c = mp[i][j];
      int p = i * m + j;
      if (c == 'U' && i + 2 < n)
        edge[(i + 2) * m + j].push_back(p);
      else if (c == 'D' && i > 1)
        edge[(i - 2) * m + j].push_back(p);
      else if (c == 'L' && j + 2 < m)
        edge[p + 2].push_back(p);
      else if (c == 'R' && j > 1)
        edge[p - 2].push_back(p);
      else
        edge[n * m].push_back(p);
    }
  dfs(n * m);
  assert(tot == n * m + 1);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      if (~(i + j) & 1) {
        char c = mp[i][j];
        int p = i * m + j, q;
        if (c == 'U')
          q = p + m;
        else if (c == 'D')
          q = p - m;
        else if (c == 'L')
          q = p + 1;
        else
          q = p - 1;
        md[beg[p]].push_back(Opt{beg[q], ed[q], 1});
        md[ed[p] + 1].push_back(Opt{beg[q], ed[q], -1});
      }
  LL ans = 0;
  for (int i = 1; i <= tot; i++) {
    for (const Opt& o : md[i]) modify(o.l, o.r, o.tp);
    ans += sum[1];
  }
  printf("%lld\n", ans);
  return 0;
}
