#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 2;
vector<long long> adj[N];
long long n, m, in[N], now = 0, out[N], it[4 * N], lazy[4 * N], cnt[4 * N],
                       link[N], ans = 0;
bool deg[N];
bool check(long long x, long long y) {
  return (x >= 0 && x < n && y >= 0 && y < m);
}
long long idx(long long x, long long y) { return x * m + y + 1; }
void gettour(long long x) {
  now++;
  in[x] = now;
  for (long long i : adj[x]) {
    gettour(i);
  }
  out[x] = now;
}
void init(long long idx, long long l, long long r) {
  cnt[idx] = r - l + 1;
  if (l == r) {
    return;
  }
  init(2 * idx, l, (l + r) / 2);
  init(2 * idx + 1, (l + r) / 2 + 1, r);
}
void push_down(long long idx, long long l, long long r) {
  if (l < r) {
    lazy[2 * idx] += lazy[idx];
    lazy[2 * idx + 1] += lazy[idx];
    it[2 * idx] += lazy[idx];
    it[2 * idx + 1] += lazy[idx];
  }
  lazy[idx] = 0;
}
void add(long long idx, long long l, long long r, long long lef, long long rig,
         long long val) {
  if (l > rig || r < lef) {
    return;
  }
  if (l >= lef && r <= rig) {
    it[idx] += val;
    lazy[idx] += val;
    return;
  }
  push_down(idx, l, r);
  add(2 * idx, l, (l + r) / 2, lef, rig, val);
  add(2 * idx + 1, (l + r) / 2 + 1, r, lef, rig, val);
  if (it[2 * idx] < it[2 * idx + 1]) {
    it[idx] = it[2 * idx];
    cnt[idx] = cnt[2 * idx];
  } else {
    it[idx] = it[2 * idx + 1];
    cnt[idx] = cnt[2 * idx + 1];
    if (it[2 * idx] == it[2 * idx + 1]) {
      cnt[idx] += cnt[2 * idx];
    }
  }
}
void dfs(long long x) {
  long long v = link[x];
  add(1, 1, now, in[v], out[v], 1);
  if (it[1] == 0) {
    ans += now - cnt[1];
  } else {
    ans += now;
  }
  for (long long i : adj[x]) {
    dfs(i);
  }
  add(1, 1, now, in[v], out[v], -1);
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long i, j, k, l;
  cin >> n >> m;
  vector<string> dime;
  dime.resize(n);
  for (i = 0; i < n; i++) {
    cin >> dime[i];
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (dime[i][j] == 'U') {
        if (check(i + 2, j)) {
          adj[idx(i + 2, j)].push_back(idx(i, j));
          deg[idx(i, j)] = true;
        }
        if ((i + j) % 2 == 0) {
          link[idx(i, j)] = idx(i + 1, j);
        }
      }
      if (dime[i][j] == 'D') {
        if (check(i - 2, j)) {
          adj[idx(i - 2, j)].push_back(idx(i, j));
          deg[idx(i, j)] = true;
        }
        if ((i + j) % 2 == 0) {
          link[idx(i, j)] = idx(i - 1, j);
        }
      }
      if (dime[i][j] == 'L') {
        if (check(i, j + 2)) {
          adj[idx(i, j + 2)].push_back(idx(i, j));
          deg[idx(i, j)] = true;
        }
        if ((i + j) % 2 == 0) {
          link[idx(i, j)] = idx(i, j + 1);
        }
      }
      if (dime[i][j] == 'R') {
        if (check(i, j - 2)) {
          adj[idx(i, j - 2)].push_back(idx(i, j));
          deg[idx(i, j)] = true;
        }
        if ((i + j) % 2 == 0) {
          link[idx(i, j)] = idx(i, j - 1);
        }
      }
    }
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (((i + j) & 1) && !deg[idx(i, j)]) {
        gettour(idx(i, j));
      }
    }
  }
  init(1, 1, now);
  for (i = 0; i < n; i++) {
    for (j = 0; j < m; j++) {
      if (!((i + j) & 1) && !deg[idx(i, j)]) {
        if (it[1] != 0 || cnt[1] != now) {
          cout << i << ' ' << j << ' ' << it[1] << ' ' << cnt[1] << endl;
          return 0;
        }
        dfs(idx(i, j));
      }
    }
  }
  cout << ans;
}
