#include <bits/stdc++.h>
using namespace std;
int getgcd(int x, int y) {
  while (x && y) (x > y) ? x %= y : y %= x;
  return x + y;
}
long long n, m, lcm, ans;
int xsz, ysz, gcd, i;
int cnt[1000001][26];
char x[1000001], y[1000001];
int main() {
  scanf("%I64d %I64d\n", &n, &m);
  scanf("%s\n", &x);
  xsz = strlen(x);
  scanf("%s\n", &y);
  ysz = strlen(y);
  gcd = getgcd(xsz, ysz);
  lcm = (1ll * xsz) / gcd * ysz;
  ans = lcm;
  for (i = 0; i < xsz; i++) {
    cnt[i % gcd][x[i] - 'a']++;
  }
  for (i = 0; i < ysz; i++) ans -= cnt[i % gcd][y[i] - 'a'];
  printf("%I64d", ans * (n * xsz / lcm));
  return 0;
}
