#include <bits/stdc++.h>
using namespace std;
const int64_t INF = 4e18, MOD = 1e9 + 7;
struct Seg {
  int64_t l, r, mid, amt;
  int64_t v = 0;
  int64_t prop = 0;
  bool resp = 0;
  Seg *lp = NULL, *rp = NULL;
  Seg(int64_t _l, int64_t _r)
      : l(_l), r(_r), mid((_l + _r) / 2), amt(_r - _l + 1) {}
  Seg* copy() { return new Seg(*this); }
  Seg* setx(int64_t first) {
    Seg* ns = copy();
    ns->prop = first;
    ns->resp = 1;
    ns->v = first * ns->amt;
    return ns;
  }
  void fix() {
    if (!lp) lp = new Seg(l, mid);
    if (!rp) rp = new Seg(mid + 1, r);
    if (resp) {
      lp = lp->setx(prop);
      rp = rp->setx(prop);
      resp = 0;
    }
    v = lp->v + rp->v;
  }
  Seg* update(int64_t a, int64_t b, int64_t first) {
    if (a > r || b < l) return this;
    if (a <= l && r <= b) return setx(first);
    fix();
    Seg* ns = copy();
    ns->lp = lp->update(a, b, first);
    ns->rp = rp->update(a, b, first);
    ns->fix();
    return ns;
  }
  int64_t query() { return v; }
};
int64_t n, m;
bool in(int64_t first, int64_t second) {
  return first >= 0 && first < n && second >= 0 && second < m;
}
int64_t conv(int64_t first, int64_t second) {
  if (!in(first, second)) return -1;
  return first * m + second;
}
pair<int64_t, int64_t> back_conv(int64_t c) { return {c / m, c % m}; }
map<char, int64_t> mconv = {{'U', 0}, {'D', 1}, {'L', 2}, {'R', 3}};
pair<int64_t, int64_t> dir[] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
vector<int64_t> board;
vector<vector<int64_t> > g;
vector<int64_t> degin;
vector<int64_t> tin, tout;
vector<int64_t> order;
void dfs(int64_t cur) {
  tin[cur] = order.size();
  order.push_back(cur);
  for (int64_t nei : g[cur]) dfs(nei);
  tout[cur] = order.size() - 1;
}
int64_t ans = 0;
void dfs2(int64_t cur, Seg* seg) {
  pair<int64_t, int64_t> pos = back_conv(cur), d = dir[board[cur]];
  int64_t other = conv(pos.first + d.first, pos.second + d.second);
  Seg* ns = seg->update(tin[other], tout[other], 1);
  ans += ns->query();
  for (auto nei : g[cur]) dfs2(nei, ns);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  g.resize(n * m);
  degin.resize(n * m, 0);
  board.resize(n * m);
  for (int64_t i = 0; i < n; i++) {
    string s;
    cin >> s;
    for (int64_t j = 0; j < m; j++) {
      int64_t me = conv(i, j);
      board[me] = mconv[s[j]];
      pair<int64_t, int64_t>& d = dir[board[me]];
      int64_t ind = conv(i + 2 * d.first, j + 2 * d.second);
      if (ind != -1) {
        g[ind].push_back(me), degin[me]++;
      }
    }
  }
  tin.resize(n * m, -1);
  tout.resize(n * m, -1);
  for (int64_t i = 0; i < n; i++)
    for (int64_t j = 0; j < m; j++)
      if ((i + j) % 2 == 1 && degin[conv(i, j)] == 0) {
        dfs(conv(i, j));
      }
  for (int64_t i = 0; i < n; i++)
    for (int64_t j = 0; j < m; j++)
      if ((i + j) % 2 == 1 && tin[conv(i, j)] == -1) cout << "FUCK!" << endl;
  Seg* seg = new Seg(0, order.size());
  for (int64_t i = 0; i < n; i++)
    for (int64_t j = 0; j < m; j++)
      if ((i + j) % 2 == 0 && degin[conv(i, j)] == 0) {
        dfs2(conv(i, j), seg);
      }
  cout << ans << endl;
  return 0;
}
