#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
vector<char> v[N];
vector<int> id[N];
vector<int> e[N];
vector<pair<int, int> > opt[N];
int n, m, nd;
int dfn[N], ed[N];
int ind[N];
void add(int x, int y) {
  e[x].push_back(y);
  ind[y] = 1;
}
void dfs(int x) {
  dfn[x] = ++*dfn;
  for (auto i : e[x]) dfs(i);
  ed[x] = *dfn;
}
void insert(int x, int y) {
  if (dfn[x] > dfn[y]) swap(x, y);
  opt[dfn[x]].push_back(pair<int, int>(y, 1));
  opt[ed[x] + 1].push_back(pair<int, int>(y, -1));
}
int cov[N * 8], t[N * 8];
void push(int k, int l, int r) {
  t[k] = (cov[k] ? r - l + 1 : t[k * 2] + t[k * 2 + 1]);
}
void change(int k, int l, int r, int x, int y, int v) {
  if (x <= l && r <= y) {
    cov[k] += v;
    return push(k, l, r);
  }
  int mid = (l + r) / 2;
  if (x <= mid) change(k * 2, l, mid, x, y, v);
  if (y > mid) change(k * 2 + 1, mid + 1, r, x, y, v);
  push(k, l, r);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (int)(0); i <= (int)(n + 1); i++) v[i].resize(m + 2);
  for (int i = (int)(0); i <= (int)(n + 1); i++) id[i].resize(m + 2);
  for (int i = (int)(1); i <= (int)(n); i++) {
    static char s[N];
    scanf("%s", s + 1);
    for (int j = (int)(1); j <= (int)(m); j++) v[i][j] = s[j];
  }
  for (int i = (int)(1); i <= (int)(n); i++)
    for (int j = (int)(1); j <= (int)(m); j++) id[i][j] = ++nd;
  for (int i = (int)(1); i <= (int)(n); i++)
    for (int j = (int)(1); j <= (int)(m); j++)
      if (v[i][j] == 'U') {
        if (i - 1 >= 1 && i + 1 <= n) add(id[i - 1][j], id[i + 1][j]);
        if (i >= 1 && i + 2 <= n) add(id[i + 2][j], id[i][j]);
      }
  for (int i = (int)(1); i <= (int)(n); i++)
    for (int j = (int)(1); j <= (int)(m); j++)
      if (v[i][j] == 'L') {
        if (j - 1 >= 1 && j + 1 <= m) add(id[i][j - 1], id[i][j + 1]);
        if (j >= 1 && j + 2 <= m) add(id[i][j + 2], id[i][j]);
      }
  for (int i = (int)(1); i <= (int)(n); i++)
    for (int j = (int)(1); j <= (int)(m); j++)
      if ((i + j) % 2 == 0 && !ind[id[i][j]]) dfs(id[i][j]);
  for (int i = (int)(1); i <= (int)(n); i++)
    for (int j = (int)(1); j <= (int)(m); j++)
      if ((i + j) % 2 == 1 && !ind[id[i][j]]) dfs(id[i][j]);
  for (int i = (int)(1); i <= (int)(n); i++)
    for (int j = (int)(1); j <= (int)(m); j++) {
      if (v[i][j] == 'U') insert(id[i][j], id[i + 1][j]);
      if (v[i][j] == 'L') insert(id[i][j], id[i][j + 1]);
    }
  long long ans = 0;
  for (int i = (int)(1); i <= (int)(n * m / 2); i++) {
    for (auto j : opt[i])
      change(1, 1, n * m, dfn[j.first], ed[j.first], j.second);
    ans += t[1];
  }
  cout << ans << endl;
}
