#include <bits/stdc++.h>
char ibuf[1 << 15], *p1, *p2;
struct {
  inline operator int() {
    register char c, f = 0;
    while ((c = (p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 1 << 15, stdin),
                              p1 == p2)
                     ? EOF
                     : *p1++)) < 48 ||
           c > 57)
      if (c == '-') f = 1;
    register int unsigned a = c & 15;
    while ((c = (p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 1 << 15, stdin),
                              p1 == p2)
                     ? EOF
                     : *p1++)) >= 48 &&
           c <= 57)
      a = a * 10 + (c & 15);
    return f ? ~a + 1 : a;
  }
  inline operator char() {
    register char c;
    while (!isgraph(
        c = (p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 1 << 15, stdin),
                          p1 == p2)
                 ? EOF
                 : *p1++)))
      ;
    return c;
  }
} g90;
const int N = 606060;
int n, m;
std::vector<std::pair<int, int> > pt;
inline int ID(int i, int j) {
  assert(i > 0 && i <= n && j > 0 && j <= m);
  return (i - 1) * m + j;
}
inline int I(int id) {
  assert(id > 0 && id <= n * m);
  return (id - 1) / m + 1;
}
inline int J(int id) {
  assert(id > 0 && id <= n * m);
  return (id - 1) % m + 1;
}
struct List {
  int last[N], next[N];
  inline void add(const int& u, const int& v) {
    next[v] = last[u], last[u] = v;
  }
  inline int operator-(const int& id) const { return last[id]; }
  inline int operator>>(const int& id) const { return next[id]; }
} G;
int k, dftime[2], fa[N], dfn[N], size[N];
void dfs(int i, int j) {
  int id = ID(i, j);
  dfn[id] = ++dftime[k], size[id] = 1;
  assert(dfn[id] <= m * n / 2 + 1);
  for (int v = G - id; v; v = G >> v) {
    dfs(I(v), J(v));
    size[id] += size[v];
  }
}
namespace ScanLine {
struct Line {
  int x, y1, y2, val;
  inline Line(int _x = 0, int _y1 = 0, int _y2 = 0, int _val = 0)
      : x(_x), y1(_y1), y2(_y2), val(_val) {}
  inline int operator<(const Line& _) const { return x < _.x; }
};
std::vector<Line> line;
struct SegTree {
  int s[N << 2], times[N << 2];
  inline void update(int l, int r, int x, int id = 1, int _l = 1,
                     int _r = n * m / 2 + 1) {
    if (r < _l || _r < l) return;
    if (l <= _l && _r <= r) {
      s[id] = (times[id] += x) ? _r - _l + 1
                               : (_l == _r ? 0 : s[id << 1] + s[id << 1 | 1]);
      return;
    }
    int _mid = _l + _r >> 1;
    update(l, r, x, id << 1, _l, _mid),
        update(l, r, x, id << 1 | 1, _mid + 1, _r);
    s[id] = times[id]  ? _r - _l + 1
            : _l == _r ? 0
                       : s[id << 1] + s[id << 1 | 1];
  }
} st;
inline void add(int x1, int y1, int x2, int y2) {
  line.push_back(Line(x1, y1, y2, 1)), line.push_back(Line(x2 + 1, y1, y2, -1));
}
inline void work() {
  sort(line.begin(), line.end());
  int64_t ans = 0;
  for (int i = 0; i < (int)line.size() - 1; i++) {
    st.update(line[i].y1, line[i].y2, line[i].val);
    ans += st.s[1] * 1ll * (line[i + 1].x - line[i].x);
  }
  printf("%lld\n", ans);
}
}  // namespace ScanLine
int main() {
  n = g90, m = g90;
  ScanLine::line.reserve(n * m + 5);
  pt.reserve((n * m >> 1) + 5);
  for (int i = 1; i <= n; i++)
    for (int j = 1, di, dj; j <= m; j++) {
      switch ((char)g90) {
        case 'L':
          di = 0, dj = 1;
          break;
        case 'R':
          di = 0, dj = -1;
          break;
        case 'U':
          di = 1, dj = 0;
          break;
        case 'D':
          di = -1, dj = 0;
          break;
      }
      if ((i ^ j) & 1 ^ 1)
        pt.push_back(std::pair<int, int>(ID(i, j), ID(i + di, j + dj)));
      int fi = i + di * 2, fj = j + dj * 2;
      if (fi < 1 || fi > n || fj < 1 || fj > m) continue;
      G.add(ID(fi, fj), ID(i, j));
      fa[ID(i, j)] = ID(fi, fj);
    }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      if (!fa[ID(i, j)]) k = (i ^ j) & 1, dfs(i, j);
  for (int i = 0; i < (int)pt.size(); i++) {
    int &u = pt[i].first, &v = pt[i].second;
    ScanLine::add(dfn[u], dfn[v], dfn[u] + size[u] - 1, dfn[v] + size[v] - 1);
  }
  ScanLine::work();
  return 0;
}
