#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5, INF = 0x3f3f3f3f;
long long n, m, ans, orz[N];
vector<long long> a[N];
struct Edge {
  long long to, next;
} e[N << 1];
long long head[N], ecnt;
void addedge(long long from, long long to) {
  swap(from, to);
  e[++ecnt] = (Edge){to, head[from]};
  head[from] = ecnt;
}
long long calc(long long x, long long y) {
  if (x < 1 || y < 1 || x > n || y > m) return 0;
  return (x - 1) * m + y;
}
long long L[N], R[N], cnt;
void dfs(long long x) {
  L[x] = ++cnt;
  for (long long i = head[x]; i; i = e[i].next) dfs(e[i].to);
  R[x] = cnt;
}
struct SGT {
  struct node {
    long long minn, sum, add;
  } t[N << 2];
  void build(long long k, long long l, long long r) {
    t[k].sum = r - l + 1;
    if (l == r) return;
    const long long mid = l + r >> 1;
    build(k << 1, l, mid), build(k << 1 | 1, mid + 1, r);
  }
  void pushup(long long k) {
    t[k].minn = min(t[k << 1].minn, t[k << 1 | 1].minn);
    t[k].sum = 0;
    if (t[k].minn == t[k << 1].minn) t[k].sum += t[k << 1].sum;
    if (t[k].minn == t[k << 1 | 1].minn) t[k].sum += t[k << 1 | 1].sum;
  }
  void pushdown(long long k) {
    t[k << 1].minn += t[k].add, t[k << 1 | 1].minn += t[k].add;
    t[k << 1].add += t[k].add, t[k << 1 | 1].add += t[k].add;
    t[k].add = 0;
  }
  void update(long long k, long long l, long long r, long long ql, long long qr,
              long long delta) {
    if (l >= ql && r <= qr) {
      t[k].minn += delta, t[k].add += delta;
      return;
    }
    const long long mid = l + r >> 1;
    pushdown(k);
    if (ql <= mid) update(k << 1, l, mid, ql, qr, delta);
    if (qr > mid) update(k << 1 | 1, mid + 1, r, ql, qr, delta);
    pushup(k);
    return;
  }
  void query(long long x) {
    if (x) {
      update(1, 1, cnt, L[orz[x]], R[orz[x]], 1);
      ans += cnt - t[1].sum;
    }
    for (long long i = head[x]; i; i = e[i].next) query(e[i].to);
    if (x) update(1, 1, cnt, L[orz[x]], R[orz[x]], -1);
  }
} T;
char s[N];
long long getnum(char ch) {
  if (ch == 'L') return 1;
  if (ch == 'R') return 2;
  if (ch == 'U') return 3;
  if (ch == 'D') return 4;
}
signed main(void) {
  scanf("%lld%lld", &n, &m);
  for (long long i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    a[i].push_back(0);
    for (long long j = 1; j <= m; j++) a[i].push_back(getnum(s[j]));
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      const long long u = calc(i, j);
      if (a[i][j] == 1) addedge(u, calc(i, j + 2)), orz[u] = calc(i, j + 1);
      if (a[i][j] == 2) addedge(u, calc(i, j - 2)), orz[u] = calc(i, j - 1);
      if (a[i][j] == 3) addedge(u, calc(i + 2, j)), orz[u] = calc(i + 1, j);
      if (a[i][j] == 4) addedge(u, calc(i - 2, j)), orz[u] = calc(i - 1, j);
    }
  }
  dfs(0);
  T.build(1, 1, cnt);
  T.query(0);
  printf("%lld\n", ans >> 1);
  return 0;
}
