#include <bits/stdc++.h>
struct event {
  int p, t;
  event() {}
  event(const int &p, const int &t) : p(p), t(t) {}
} p[200010];
char pl[200010];
char *a[200010];
bool vis[200010];
int nxt[200010], head[200010], dfn[200010], out[200010];
int mn[200010 << 2], cnt[200010 << 2], tag[200010 << 2];
inline void add(const int &x, const int &y) {
  nxt[y] = head[x];
  head[x] = y;
  vis[y] = true;
}
void dfs(const int &f) {
  static int cnt;
  dfn[f] = ++cnt;
  for (int t = head[f]; ~t; t = nxt[t]) dfs(t);
  out[f] = cnt;
}
inline void mark(const int &o, const int &v) {
  mn[o] += v;
  tag[o] += v;
}
void build(const int &o, const int &l, const int &r) {
  cnt[o] = r - l + 1;
  if (l == r) return;
  const int mid = (l + r) >> 1;
  build(o << 1, l, mid);
  build(o << 1 | 1, mid + 1, r);
}
void modify(const int &o, const int &l, const int &r, const int &L,
            const int &R, const int &v) {
  if (L <= l && r <= R) {
    mark(o, v);
    return;
  }
  const int mid = (l + r) >> 1;
  if (tag[o]) {
    mark(o << 1, tag[o]);
    mark(o << 1 | 1, tag[o]);
    tag[o] = 0;
  }
  if (L <= mid) modify(o << 1, l, mid, L, R, v);
  if (mid < R) modify(o << 1 | 1, mid + 1, r, L, R, v);
  mn[o] = std::min(mn[o << 1], mn[o << 1 | 1]);
  cnt[o] = 0;
  if (mn[o] == mn[o << 1]) cnt[o] += cnt[o << 1];
  if (mn[o] == mn[o << 1 | 1]) cnt[o] += cnt[o << 1 | 1];
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  const int s = n * m;
  for (int i = 0; i != s; ++i) head[i] = -1;
  a[0] = pl;
  for (int i = 0; i != n; ++i) {
    scanf("%s", a[i]);
    a[i + 1] = a[i] + m;
  }
  for (int i = 0, k = 0; i != n; ++i) {
    for (int j = 0; j != m; ++j, ++k) {
      if (i + 2 < n && a[i][j] == 'U') add(k + m * 2, k);
      if (i - 2 >= 0 && a[i][j] == 'D') add(k - m * 2, k);
      if (j + 2 < m && a[i][j] == 'L') add(k + 2, k);
      if (j - 2 >= 0 && a[i][j] == 'R') add(k - 2, k);
    }
  }
  for (int i = 0; i != s; ++i) {
    if (!vis[i]) dfs(i);
  }
  for (int i = 0; i != s; ++i) head[i] = 0;
  for (int i = 0, k = 0, c = 0; i != n; ++i) {
    for (int j = 0; j != m; ++j, ++k) {
      if (!a[i][j]) continue;
      int x = k, y = 0;
      switch (a[i][j]) {
        case 'U': {
          y = x + m;
          break;
        }
        case 'D': {
          y = x - m;
          break;
        }
        case 'L': {
          y = x + 1;
          break;
        }
        case 'R': {
          y = x - 1;
          break;
        }
      }
      pl[x] = 0;
      pl[y] = 0;
      if ((i ^ j) & 1) std::swap(x, y);
      p[++c] = event(y, 1);
      add(dfn[x], c);
      p[++c] = event(y, -1);
      add(out[x] + 1, c);
    }
  }
  build(1, 1, s);
  long long ans = 0;
  for (int i = 1; i <= s; ++i) {
    for (int j = head[i]; j; j = nxt[j]) {
      modify(1, 1, s, dfn[p[j].p], out[p[j].p], p[j].t);
    }
    if (!mn[1]) ans += s - cnt[1];
  }
  printf("%lld\n", ans);
  return 0;
}
