#include <bits/stdc++.h>
template <typename T>
bool chkmax(T &x, T y) {
  return x < y ? x = y, true : false;
}
template <typename T>
bool chkmin(T &x, T y) {
  return x > y ? x = y, true : false;
}
using namespace std;
long long ksm(long long a, long long b) {
  if (!b) return 1;
  long long ns = ksm(a, b >> 1);
  ns = ns * ns % 998244353;
  if (b & 1) ns = ns * a % 998244353;
  return ns;
}
struct ST {
  int l, r;
  ST *ch[2];
  int lz;
  pair<int, int> q;
} p[200005 * 3], *root;
int stcnt = 0;
pair<int, int> u(pair<int, int> x, pair<int, int> y) {
  if (x.first > y.first) swap(x, y);
  if (y.first == x.first) x.second += y.second;
  return x;
}
void upd(ST *a) { a->q = u(a->ch[0]->q, a->ch[1]->q); }
void bdtree(ST *a, int l, int r) {
  a->q = make_pair(0, r - l + 1);
  a->l = l, a->r = r, a->lz = 0;
  if (l == r) return;
  int mid = (l + r) >> 1;
  a->ch[0] = &p[stcnt++], a->ch[1] = &p[stcnt++];
  bdtree(a->ch[0], l, mid), bdtree(a->ch[1], mid + 1, r);
}
void actlz(ST *a, int lz) {
  a->lz += lz;
  a->q.first += lz;
}
void pushdown(ST *a) {
  if (a->lz) {
    actlz(a->ch[0], a->lz);
    actlz(a->ch[1], a->lz);
    a->lz = 0;
  }
}
void push(ST *a, int l, int r, int lz) {
  if (l > r) return;
  if (a->l == l && a->r == r) {
    actlz(a, lz);
    return;
  }
  int mid = (a->l + a->r) >> 1;
  pushdown(a);
  if (r <= mid)
    push(a->ch[0], l, r, lz);
  else if (l > mid)
    push(a->ch[1], l, r, lz);
  else
    push(a->ch[0], l, mid, lz), push(a->ch[1], mid + 1, r, lz);
  upd(a);
}
vector<pair<int, pair<int, int> > > acts;
void work() {
  root = &p[stcnt++];
  bdtree(root, 1, 200005);
  sort(acts.begin(), acts.end());
  long long ans = 0;
  for (int i = 0; i < acts.size(); i++) {
    if (i) {
      int nt = acts[i].first - acts[i - 1].first;
      int tot = 200005 - root->q.second;
      ans += 1ll * nt * tot;
    }
    pair<int, int> um = acts[i].second;
    int tp = 1;
    if (um.first < 0) {
      tp *= -1;
      um.first *= -1, um.second *= -1;
    }
    push(root, um.first, um.second, tp);
  }
  cout << ans << endl;
}
int n, m;
char inp[200005];
int tp[200005];
int bl[200005];
int nx[200005];
vector<int> eg[200005];
int fa[200005];
int dfn[200005], sz[200005], tf[200005];
int id(int x, int y) { return (x - 1) * m + y; }
pair<int, int> tran(int x) {
  int u = (x - 1) / m + 1, v = x % m;
  if (v == 0) v = m;
  return make_pair(u, v);
}
int dfcnt = 0;
void dfs(int a) {
  dfn[a] = ++dfcnt;
  sz[a] = 1;
  for (auto v : eg[a]) {
    if (v == fa[a]) continue;
    fa[v] = a;
    tf[v] = tf[a];
    dfs(v);
    sz[a] += sz[v];
  }
}
vector<pair<int, int> > gt(int u, int v) {
  vector<pair<int, int> > res;
  if (v == fa[u])
    res.push_back(make_pair(dfn[u], dfn[u] + sz[u] - 1));
  else {
    int pre = tf[u];
    int st = dfn[pre], ed = dfn[pre] + sz[pre] - 1;
    if (v == 0)
      res.push_back(make_pair(st, ed));
    else {
      res.push_back(make_pair(st, dfn[v] - 1));
      res.push_back(make_pair(dfn[v] + sz[v], ed));
    }
  }
  return res;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    scanf("%s", inp + 1);
    for (int j = 1; j <= m; j++) {
      int nid = id(i, j), eid;
      if (inp[j] == 'U')
        eid = id(i + 1, j);
      else if (inp[j] == 'L')
        eid = id(i, j + 1);
      else if (inp[j] == 'D')
        eid = id(i - 1, j);
      else if (inp[j] == 'R')
        eid = id(i, j - 1);
      bl[nid] = eid;
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      int nid = id(i, j);
      pair<int, int> v = tran(bl[nid]);
      pair<int, int> ed = make_pair(2 * v.first - i, 2 * v.second - j);
      if (ed.first <= 0 || ed.second <= 0 || ed.first > n || ed.second > m)
        continue;
      else {
        nx[nid] = id(ed.first, ed.second);
        eg[nid].push_back(nx[nid]), eg[nx[nid]].push_back(nid);
      }
    }
  for (int i = 1; i <= n * m; i++)
    if (!dfn[i]) tf[i] = i, dfs(i);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if ((i + j) % 2 == 0) continue;
      int u = id(i, j), v = bl[u];
      vector<pair<int, int> > xu = gt(u, nx[u]), xv = gt(v, nx[v]);
      for (auto h : xu)
        for (auto m : xv)
          acts.push_back(make_pair(h.first, m)),
              acts.push_back(
                  make_pair(h.second + 1, make_pair(-m.first, -m.second)));
    }
  work();
  return 0;
}
