#include <bits/stdc++.h>
using namespace std;
long long gi() {
  char cc = getchar();
  long long cn = 0, flus = 1;
  while (cc < '0' || cc > '9') {
    if (cc == '-') flus = -flus;
    cc = getchar();
  }
  while (cc >= '0' && cc <= '9') cn = cn * 10 + cc - '0', cc = getchar();
  return cn * flus;
}
const long long N = 2e5 + 5;
long long n, m, lim, cnt, Ans, L[N], R[N], g[N];
vector<long long> a[N], G[N];
char s[N];
void add(long long x, long long y) { G[y].push_back(x); }
struct Tr {
  long long mi, w, tag;
} tr[N << 2];
long long Id(long long x, long long y) {
  if (x < 1 || y < 1 || x > n || y > m) return 0;
  return (x - 1) * m + y;
}
void pushup(long long x) {
  tr[x].mi = min(tr[(x << 1)].mi, tr[(x << 1 | 1)].mi), tr[x].w = 0;
  if (tr[x].mi == tr[(x << 1)].mi) tr[x].w += tr[(x << 1)].w;
  if (tr[x].mi == tr[(x << 1 | 1)].mi) tr[x].w += tr[(x << 1 | 1)].w;
}
void pushmark(long long x) {
  long long u = tr[x].tag;
  tr[x].tag = 0;
  tr[(x << 1)].mi += u, tr[(x << 1 | 1)].mi += u, tr[(x << 1)].tag += u,
      tr[(x << 1 | 1)].tag += u;
}
void update(long long x, long long l, long long r, long long ql, long long qr,
            long long k) {
  if (ql <= l && r <= qr) return tr[x].mi += k, tr[x].tag += k, void();
  if (l > qr || r < ql) return;
  long long mid = (l + r) >> 1;
  pushmark(x);
  update((x << 1), l, mid, ql, qr, k),
      update((x << 1 | 1), mid + 1, r, ql, qr, k), pushup(x);
}
void dfs(long long x) {
  L[x] = ++cnt;
  for (long long v : G[x]) dfs(v);
  R[x] = cnt;
}
void build(long long x, long long l, long long r) {
  tr[x].w = r - l + 1;
  if (l == r) return;
  long long mid = (l + r) >> 1;
  build((x << 1), l, mid), build((x << 1 | 1), mid + 1, r);
}
void Dfs(long long x) {
  if (x) {
    update(1, 1, cnt, L[g[x]], R[g[x]], 1);
    Ans += (cnt - tr[1].w);
  }
  for (long long v : G[x]) Dfs(v);
  if (x) update(1, 1, cnt, L[g[x]], R[g[x]], -1);
}
signed main() {
  n = gi(), m = gi(), lim = n * m;
  for (register long long i = (1); i <= (n); ++i) {
    scanf("%s", s + 1), a[i].push_back(0);
    for (register long long j = (1); j <= (m); ++j) {
      if (s[j] == 'L') a[i].push_back(1);
      if (s[j] == 'R') a[i].push_back(2);
      if (s[j] == 'U') a[i].push_back(3);
      if (s[j] == 'D') a[i].push_back(4);
    }
  }
  for (register long long i = (1); i <= (n); ++i)
    for (register long long j = (1); j <= (m); ++j) {
      long long u = Id(i, j);
      if (a[i][j] == 1) add(u, Id(i, j + 2)), g[u] = Id(i, j + 1);
      if (a[i][j] == 2) add(u, Id(i, j - 2)), g[u] = Id(i, j - 1);
      if (a[i][j] == 3) add(u, Id(i + 2, j)), g[u] = Id(i + 1, j);
      if (a[i][j] == 4) add(u, Id(i - 2, j)), g[u] = Id(i - 1, j);
    }
  dfs(0), build(1, 1, cnt), Dfs(0);
  cout << Ans / 2 << endl;
  return 0;
}
