#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long w = 0, f = 1;
  char c = ' ';
  while (c < '0' || c > '9') c = getchar(), f = c == '-' ? -1 : f;
  while (c >= '0' && c <= '9') w = w * 10 + c - 48, c = getchar();
  return w * f;
}
long long read14() {
  char c = getchar();
  while (c != 'U' && c != 'D' && c != 'L' && c != 'R') c = getchar();
  if (c == 'U') return 1;
  if (c == 'D') return 2;
  if (c == 'L') return 3;
  return 4;
}
long long n, m, p[200005], dl[200005], dr[200005];
vector<long long> a[200005], e[200005];
long long pos(long long x, long long y) {
  if (x >= 1 && x <= n && y >= 1 && y <= m) return (x - 1) * m + y;
  return n * m + 1 + ((x + y) & 1);
}
long long minn[200005 << 2], tag[200005 << 2], val[200005 << 2];
void build(long long p, long long l, long long r) {
  if (l == r) {
    val[p] = 1;
    return;
  }
  long long mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  val[p] = val[p << 1] + val[p << 1 | 1];
}
void down(long long p, long long l, long long r) {
  if (!tag[p]) return;
  minn[p << 1] += tag[p];
  minn[p << 1 | 1] += tag[p];
  tag[p << 1] += tag[p];
  tag[p << 1 | 1] += tag[p];
  tag[p] = 0;
}
void update(long long p, long long x, long long y, long long v, long long l,
            long long r) {
  if (x <= l && y >= r) {
    minn[p] += v, tag[p] += v;
    return;
  }
  down(p, l, r);
  long long mid = (l + r) >> 1;
  if (x <= mid) update(p << 1, x, y, v, l, mid);
  if (y > mid) update(p << 1 | 1, x, y, v, mid + 1, r);
  if (minn[p << 1] == minn[p << 1 | 1])
    val[p] = val[p << 1] + val[p << 1 | 1];
  else if (minn[p << 1] < minn[p << 1 | 1])
    val[p] = val[p << 1];
  else
    val[p] = val[p << 1 | 1];
  minn[p] = min(minn[p << 1], minn[p << 1 | 1]);
}
long long now, ans;
void dfs1(long long u) {
  dl[u] = ++now;
  for (auto v : e[u]) dfs1(v);
  dr[u] = now;
}
void dfs2(long long u, long long rt) {
  if (u != rt) update(1, dl[p[u]], dr[p[u]], 1, 1, now), ans -= val[1] - 1;
  for (auto v : e[u]) dfs2(v, rt);
  if (u != rt) update(1, dl[p[u]], dr[p[u]], -1, 1, now);
}
signed main() {
  n = read(), m = read(), ans = n * n * m * m / 4;
  for (long long i = 1; i <= n; i++) {
    a[i].push_back(0);
    for (long long j = 1; j <= m; j++) {
      a[i].push_back(read14());
      if (a[i][j] == 1)
        e[pos(i + 2, j)].push_back(pos(i, j)), p[pos(i, j)] = pos(i + 1, j);
      if (a[i][j] == 2)
        e[pos(i - 2, j)].push_back(pos(i, j)), p[pos(i, j)] = pos(i - 1, j);
      if (a[i][j] == 3)
        e[pos(i, j + 2)].push_back(pos(i, j)), p[pos(i, j)] = pos(i, j + 1);
      if (a[i][j] == 4)
        e[pos(i, j - 2)].push_back(pos(i, j)), p[pos(i, j)] = pos(i, j - 1);
    }
  }
  dfs1(n * m + 1);
  build(1, 1, now);
  dfs2(n * m + 2, n * m + 2);
  printf("%lld", ans);
  return 0;
}
