#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void read(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void readc(char &x) {
  char c;
  while (((c = getchar()) == ' ') || c == '\n')
    ;
  x = c;
}
long long ans;
int n, m, i, j, first[200005], ed[200005], deg[200005], ti;
vector<int> e[200005];
char mp[200005];
int id(int x, int y) { return (x - 1) * m + y; }
void dfs(int x) {
  first[x] = ++ti;
  for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++) {
    dfs(*it);
  }
  ed[x] = ti;
}
struct lne {
  int h, l, r, v;
} b[200005];
int cnt;
bool cmp(lne x, lne y) { return x.h < y.h; }
void ins(int x, int xx, int y, int yy) {
  b[++cnt] = (lne){y, x, xx, 1};
  b[++cnt] = (lne){yy + 1, x, xx, -1};
}
int tag[800005], sum[800005], len[800005];
void pushup(int x) {
  if (tag[x])
    sum[x] = len[x];
  else
    sum[x] = sum[x + x] + sum[x + x + 1];
}
void upd(int x, int c, bool f) {
  tag[x] += c;
  if (f)
    sum[x] = !!tag[x];
  else
    pushup(x);
}
void build(int x, int l, int r) {
  len[x] = r - l + 1;
  if (l == r) return;
  int mid = (l + r) / 2;
  build(x + x, l, mid);
  build(x + x + 1, mid + 1, r);
}
void update(int x, int l, int r, int ql, int qr, int c) {
  if (ql <= l && r <= qr) {
    upd(x, c, l == r);
    return;
  }
  int mid = (l + r) / 2;
  if (ql <= mid) update(x + x, l, mid, ql, qr, c);
  if (qr > mid) update(x + x + 1, mid + 1, r, ql, qr, c);
  pushup(x);
}
int main() {
  read(n);
  read(m);
  for (((i)) = (1); ((i)) <= ((n * m)); ((i))++) readc(mp[i]);
  for (((i)) = (1); ((i)) <= ((n)); ((i))++)
    for (((j)) = (1); ((j)) <= ((m)); ((j))++) {
      if (mp[id(i, j)] == 'U') {
        if (i + 2 <= n) e[id(i + 2, j)].push_back(id(i, j));
        if (i - 1 >= 1) e[id(i - 1, j)].push_back(id(i + 1, j));
      }
      if (mp[id(i, j)] == 'L') {
        if (j + 2 <= m) e[id(i, j + 2)].push_back(id(i, j));
        if (j - 1 >= 1) e[id(i, j - 1)].push_back(id(i, j + 1));
      }
    }
  for (((i)) = (1); ((i)) <= ((n * m)); ((i))++)
    for (__typeof((e[i]).begin()) it = (e[i]).begin(); it != (e[i]).end(); it++)
      deg[*it]++;
  for (((i)) = (1); ((i)) <= ((n * m)); ((i))++)
    if (!deg[i]) dfs(i);
  for (((i)) = (1); ((i)) <= ((n)); ((i))++)
    for (((j)) = (1); ((j)) <= ((m)); ((j))++)
      if ((i + j) & 1) {
        if (mp[id(i, j)] == 'U') {
          ins(first[id(i, j)], ed[id(i, j)], first[id(i + 1, j)],
              ed[id(i + 1, j)]);
        }
        if (mp[id(i, j)] == 'D') {
          ins(first[id(i, j)], ed[id(i, j)], first[id(i - 1, j)],
              ed[id(i - 1, j)]);
        }
        if (mp[id(i, j)] == 'L') {
          ins(first[id(i, j)], ed[id(i, j)], first[id(i, j + 1)],
              ed[id(i, j + 1)]);
        }
        if (mp[id(i, j)] == 'R') {
          ins(first[id(i, j)], ed[id(i, j)], first[id(i, j - 1)],
              ed[id(i, j - 1)]);
        }
      }
  sort(b + 1, b + cnt + 1, cmp);
  j = 1;
  build(1, 1, ti);
  for (((i)) = (1); ((i)) <= ((ti + 1)); ((i))++) {
    ans += sum[1];
    while (j <= cnt && b[j].h == i) {
      update(1, 1, ti, b[j].l, b[j].r, b[j].v);
      j++;
    }
  }
  cout << ans << endl;
  return 0;
}
