#include <bits/stdc++.h>
using namespace std;
int n, m, c, l[200005], r[200005], g[800005];
char *s[200005];
bool f[200005];
vector<int> e[200005];
vector<pair<int, int> > a[200005], b[200005];
struct bxt {
  int u, v;
  inline bxt(int _u = 0, int _v = 1) : u(_u), v(_v) {}
  inline bxt &operator+=(const bxt &op) {
    if (u > op.u)
      *this = op;
    else if (u == op.u)
      v += op.v;
    return *this;
  }
  inline bxt operator+(const bxt &op) {
    bxt w = *this;
    return w += op;
  }
} t[800005];
inline void sdfa(int u) {
  l[u] = ++c;
  for (auto i : e[u]) sdfa(i);
  r[u] = c;
}
void build(int u = 1, int v = c, int w = 1) {
  if (u == v) return;
  int x = (u + v) >> 1;
  build(u, x, w << 1);
  build(x + 1, v, w << 1 | 1);
  t[w] = t[w << 1] + t[w << 1 | 1];
}
void modify(int ml, int mr, int mv, int u = 1, int v = c, int w = 1) {
  if (ml <= u && mr >= v) {
    g[w] += mv;
    t[w].u += mv;
    return;
  }
  t[w << 1].u += g[w];
  t[w << 1 | 1].u += g[w];
  g[w << 1] += g[w];
  g[w << 1 | 1] += g[w];
  g[w] = 0;
  int x = (u + v) >> 1;
  if (ml <= x) modify(ml, mr, mv, u, x, w << 1);
  if (mr > x) modify(ml, mr, mv, x + 1, v, w << 1 | 1);
  t[w] = t[w << 1] + t[w << 1 | 1];
}
int main() {
  int u = 0;
  long long v = 0;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    s[i] = new char[m + 5];
    scanf("%s", s[i]);
    for (int j = 0; j < m; ++u, ++j) {
      if (s[i][j] == 68) {
        if (i > 1) {
          e[u - (m << 1)].emplace_back(u);
          f[u] = true;
        }
        if (i < n - 1) {
          e[u + m].emplace_back(u - m);
          f[u - m] = true;
        }
      } else if (s[i][j] == 82) {
        if (j > 1) {
          e[u - 2].emplace_back(u);
          f[u] = true;
        }
        if (j < m - 1) {
          e[u + 1].emplace_back(u - 1);
          f[u - 1] = true;
        }
      }
    }
  }
  u = n * m;
  for (int i = 0; i < u; ++i)
    if (!f[i]) sdfa(i);
  u = 0;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++u, ++j) {
      if (s[i][j] == 68) {
        if ((i + j) & 1) {
          a[l[u - m]].emplace_back(l[u], r[u]);
          b[r[u - m]].emplace_back(l[u], r[u]);
        } else {
          a[l[u]].emplace_back(l[u - m], r[u - m]);
          b[r[u]].emplace_back(l[u - m], r[u - m]);
        }
      } else if (s[i][j] == 82) {
        if ((i + j) & 1) {
          a[l[u - 1]].emplace_back(l[u], r[u]);
          b[r[u - 1]].emplace_back(l[u], r[u]);
        } else {
          a[l[u]].emplace_back(l[u - 1], r[u - 1]);
          b[r[u]].emplace_back(l[u - 1], r[u - 1]);
        }
      }
    }
  build();
  for (int i = 1; i <= c; ++i) {
    for (const auto &j : a[i]) modify(j.first, j.second, 1);
    v += c - t[1].v;
    for (const auto &j : b[i]) modify(j.first, j.second, -1);
  }
  printf("%lld", v);
  return 0;
}
