#include <bits/stdc++.h>
using namespace std;
struct type {
  int x, Y1, Y2, s;
} b[800001];
int N, n, m, i, j, k, l, x, y, tot;
int tr[800001][2];
int Tr[800001];
int a[2000001][2], ls[200001], len;
char A[2000001], ch;
int bg[2000001], ed[2000001];
bool bz[2000001];
long long ans;
bool cmp(type a, type b) { return a.x < b.x; }
void Add(int X1, int Y1, int X2, int Y2) {
  b[++tot] = type{X1, X2, Y2, 1};
  b[++tot] = {Y1 + 1, X2, Y2, -1};
}
void New(int x, int y) {
  ++len;
  a[len][0] = y;
  a[len][1] = ls[x];
  ls[x] = len;
  bz[y] = 1;
}
void dfs(int t) {
  int i;
  bg[t] = ++j;
  for (i = ls[t]; i; i = a[i][1]) dfs(a[i][0]);
  ed[t] = j;
}
void down(int t, int len) {
  if (Tr[t]) {
    if (len > 1) Tr[t * 2] += Tr[t], Tr[t * 2 + 1] += Tr[t];
    tr[t][0] += Tr[t], Tr[t] = 0;
  }
}
void up(int t) {
  if (tr[t * 2][0] < tr[t * 2 + 1][0])
    tr[t][0] = tr[t * 2][0], tr[t][1] = tr[t * 2][1];
  else if (tr[t * 2][0] > tr[t * 2 + 1][0])
    tr[t][0] = tr[t * 2 + 1][0], tr[t][1] = tr[t * 2 + 1][1];
  else
    tr[t][0] = tr[t * 2][0], tr[t][1] = tr[t * 2][1] + tr[t * 2 + 1][1];
}
void mt(int t, int l, int r) {
  int mid = (l + r) / 2;
  tr[t][1] = r - l + 1;
  if (l == r) return;
  mt(t * 2, l, mid), mt(t * 2 + 1, mid + 1, r);
}
void change(int t, int l, int r, int x, int y, int s) {
  int mid = (l + r) / 2;
  down(t, r - l + 1);
  if (x <= l && r <= y) {
    Tr[t] += s;
    down(t, r - l + 1);
    return;
  }
  down(t * 2, mid - l + 1), down(t * 2 + 1, r - mid);
  if (x <= mid) change(t * 2, l, mid, x, y, s);
  if (mid < y) change(t * 2 + 1, mid + 1, r, x, y, s);
  up(t);
}
int main() {
  scanf("%d%d", &n, &m);
  N = n * m;
  for (i = 1; i <= n; i++)
    for (j = 1; j <= m; j++) {
      ch = getchar();
      while (ch < 'A' || ch > 'Z') ch = getchar();
      A[(((i)-1) * m + (j))] = ch;
    }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      l = (((i)-1) * m + (j));
      switch (A[l]) {
        case 'U': {
          if (i > 1) New((((i - 1) - 1) * m + (j)), (((i + 1) - 1) * m + (j)));
          break;
        }
        case 'D': {
          if (i < n) New((((i + 1) - 1) * m + (j)), (((i - 1) - 1) * m + (j)));
          break;
        }
        case 'L': {
          if (j > 1) New((((i)-1) * m + (j - 1)), (((i)-1) * m + (j + 1)));
          break;
        }
        case 'R': {
          if (j < m) New((((i)-1) * m + (j + 1)), (((i)-1) * m + (j - 1)));
          break;
        }
      }
    }
  }
  j = 0;
  for (i = 1; i <= n * m; i++)
    if (!bz[i]) dfs(i);
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= m; j++) {
      k = (((i)-1) * m + (j));
      if (A[k] == 'U')
        l = (((i + 1) - 1) * m + (j)), Add(bg[k], ed[k], bg[l], ed[l]),
        Add(bg[l], ed[l], bg[k], ed[k]);
      else if (A[k] == 'L')
        l = (((i)-1) * m + (j + 1)), Add(bg[k], ed[k], bg[l], ed[l]),
        Add(bg[l], ed[l], bg[k], ed[k]);
    }
  }
  sort(b + 1, b + tot + 1, cmp);
  mt(1, 1, N);
  for (i = 1; i <= tot; i++) {
    if (i > 1 && b[i].x != b[i - 1].x)
      ans += 1ll * (N - (tr[1][0] == 0) * tr[1][1]) * (b[i].x - b[i - 1].x);
    change(1, 1, N, b[i].Y1, b[i].Y2, b[i].s);
  }
  printf("%lld\n", ans / 2);
  fclose(stdin);
  fclose(stdout);
  return 0;
}
