#include <bits/stdc++.h>
using namespace std;
const int N = 200003, mod = 998244353;
template <typename T>
void read(T &x) {
  int ch = getchar();
  x = 0;
  bool f = false;
  for (; ch < '0' || ch > '9'; ch = getchar())
    ;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  if (f) x = -x;
}
template <typename T>
bool chmax(T &a, const T &b) {
  if (a < b) return a = b, 1;
  return 0;
}
template <typename T>
bool chmin(T &a, const T &b) {
  if (a > b) return a = b, 1;
  return 0;
}
void qmo(int &x) { x += x >> 31 & mod; }
int ksm(int a, int b) {
  int res = 1;
  for (; b; b >>= 1, a = (long long)a * a % mod)
    if (b & 1) res = (long long)res * a % mod;
  return res;
}
int n, m, cnt, head[N], to[N << 2], nxt[N << 2], pos[N], dfn[N], out[N], tim;
string S[N];
vector<pair<int, int> > pre[N];
char str[N];
bool notrt[N];
void add(int a, int b) {
  static int ect = 0;
  notrt[b] = true;
  to[++ect] = b;
  nxt[ect] = head[a];
  head[a] = ect;
}
void dfs(int x, int f = 0) {
  dfn[x] = ++tim;
  for (int i = head[x]; i; i = nxt[i])
    if (to[i] != f) dfs(to[i], x);
  out[x] = tim;
}
int id(int x, int y) { return (x - 1) * m + y; }
struct Node {
  int op, l, r;
  Node(int _l = 0, int _r = 0, int _o = 0) : op(_o), l(_l), r(_r) {}
};
vector<Node> vec[N << 2];
void addq(int l1, int r1, int l2, int r2) {
  vec[l1].emplace_back(l2, r2, 1);
  vec[r1 + 1].emplace_back(l2, r2, -1);
}
int mix[N << 2], mct[N << 2], tag[N << 2];
long long ans;
void pushup(int x) {
  mix[x] = min(mix[x << 1], mix[x << 1 | 1]);
  mct[x] = 0;
  if (mix[x] == mix[x << 1]) mct[x] = mct[x << 1];
  if (mix[x] == mix[x << 1 | 1]) mct[x] += mct[x << 1 | 1];
}
void pushadd(int x, int v) {
  mix[x] += v;
  tag[x] += v;
}
void pushdown(int x) {
  if (tag[x]) {
    pushadd(x << 1, tag[x]);
    pushadd(x << 1 | 1, tag[x]);
    tag[x] = 0;
  }
}
void build(int x = 1, int L = 1, int R = tim) {
  if (L == R) {
    mct[x] = 1;
    mix[x] = 0;
    return;
  }
  int mid = L + R >> 1;
  build(x << 1, L, mid);
  build(x << 1 | 1, mid + 1, R);
  pushup(x);
}
void upd(int l, int r, int v, int x = 1, int L = 1, int R = tim) {
  if (l <= L && R <= r) {
    pushadd(x, v);
    return;
  }
  int mid = L + R >> 1;
  pushdown(x);
  if (l <= mid) upd(l, r, v, x << 1, L, mid);
  if (mid < r) upd(l, r, v, x << 1 | 1, mid + 1, R);
  pushup(x);
}
int main() {
  read(n);
  read(m);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", str + 1);
    S[i].resize(m + 1);
    for (int j = 1; j <= m; ++j) S[i][j] = str[j];
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j) {
      int now = id(i, j);
      if (i <= n - 2 && S[i + 1][j] == 'U' && S[i + 2][j] == 'D')
        add(now, now + 2 * m);
      if (i > 2 && S[i - 1][j] == 'D' && S[i - 2][j] == 'U')
        add(now, now - 2 * m);
      if (j <= m - 2 && S[i][j + 1] == 'L' && S[i][j + 2] == 'R')
        add(now, now + 2);
      if (j > 2 && S[i][j - 1] == 'R' && S[i][j - 2] == 'L') add(now, now - 2);
      if (!pos[now]) {
        pos[now] = ++cnt;
        if (S[i][j] == 'L')
          pos[now + 1] = cnt;
        else if (S[i][j] == 'U')
          pos[now + m] = cnt;
      }
      pre[pos[now]].emplace_back(i, j);
    }
  for (int i = 1; i <= n * m; ++i)
    if (!notrt[i]) dfs(i);
  for (int i = 1; i <= cnt; ++i) {
    int xa = pre[i][0].first, ya = pre[i][0].second, xb = pre[i][1].first,
        yb = pre[i][1].second;
    if (xa + ya & 1) {
      swap(xa, xb);
      swap(ya, yb);
    }
    int a = id(xa, ya), b = id(xb, yb);
    addq(dfn[a], out[a], dfn[b], out[b]);
  }
  build();
  for (int i = 1; i <= tim; ++i) {
    for (Node &o : vec[i]) upd(o.l, o.r, o.op);
    ans += tim - (mix[1] ? 0 : mct[1]);
  }
  printf("%lld\n", ans);
}
