#include <bits/stdc++.h>
using namespace std;
int n, m;
char in[1000000 + 5];
vector<char> s[1000000 + 5];
inline int getId(int i, int j) {
  if (i < 1 || j < 1 || i > n || j > m)
    return 0;
  else
    return (i - 1) * m + j;
}
vector<int> E[1000000 + 5];
void add_edge(int u, int v) { E[u].push_back(v); }
int dfnl[1000000 + 5], dfnr[1000000 + 5], tim;
void dfs(int x) {
  dfnl[x] = ++tim;
  for (int y : E[x]) dfs(y);
  dfnr[x] = tim;
}
namespace scanLine {
struct line {
  long long ly, ry;
  int sign;
  line() {}
  line(int _ly, int _ry, int _sign) { ly = _ly, ry = _ry, sign = _sign; }
};
vector<line> a[1000000 + 5];
struct segment_tree {
  struct node {
    int l, r;
    long long cnt;
    long long sum;
  } tree[1000000 * 4 + 5];
  void push_up(int x) {
    if (tree[x].cnt)
      tree[x].sum = tree[x].r - tree[x].l + 1;
    else
      tree[x].sum = tree[x << 1].sum + tree[x << 1 | 1].sum;
  }
  void build(int l, int r, int pos) {
    tree[pos].l = l;
    tree[pos].r = r;
    if (l == r) return;
    int mid = (l + r) >> 1;
    build(l, mid, pos << 1);
    build(mid + 1, r, pos << 1 | 1);
    push_up(pos);
  }
  void update(int L, int R, int val, int pos) {
    if (L > tree[pos].r || R < tree[pos].l) return;
    if (L <= tree[pos].l && R >= tree[pos].r) {
      tree[pos].cnt += val;
      push_up(pos);
      return;
    }
    update(L, R, val, pos << 1);
    update(L, R, val, pos << 1 | 1);
    push_up(pos);
  }
} T;
void addSqr(int x1, int y1, int x2, int y2) {
  a[x1].push_back(line(y1, y2, 1));
  a[x2 + 1].push_back(line(y1, y2, -1));
}
long long solve() {
  long long ans = 0;
  T.build(1, tim, 1);
  for (int i = 1; i <= tim; i++) {
    for (auto p : a[i]) T.update(p.ly, p.ry, p.sign, 1);
    ans += T.tree[1].sum;
  }
  return ans;
}
}  // namespace scanLine
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", in + 1);
    s[i].resize(m + 1);
    for (int j = 1; j <= m; j++) s[i][j] = in[j];
    for (int j = 1; j <= m; j++) {
      if (s[i][j] == 'U')
        add_edge(getId(i + 2, j), getId(i, j));
      else if (s[i][j] == 'D')
        add_edge(getId(i - 2, j), getId(i, j));
      else if (s[i][j] == 'L')
        add_edge(getId(i, j + 2), getId(i, j));
      else if (s[i][j] == 'R')
        add_edge(getId(i, j - 2), getId(i, j));
    }
  }
  dfs(0);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      int x = getId(i, j), y;
      if (s[i][j] == 'U') y = getId(i + 1, j);
      if (s[i][j] == 'L') y = getId(i, j + 1);
      if (s[i][j] == 'D') y = getId(i - 1, j);
      if (s[i][j] == 'R') y = getId(i, j - 1);
      scanLine::addSqr(dfnl[x], dfnl[y], dfnr[x], dfnr[y]);
    }
  }
  printf("%lld\n", scanLine::solve() / 2);
}
