#include <bits/stdc++.h>
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int ch[1000005][26];
char s1[1000005], s2[1000005];
int main() {
  long long n, m, g, lcm, sum;
  scanf("%I64d%I64d", &n, &m);
  scanf("%s%s", s1, s2);
  long long l1, l2;
  l1 = strlen(s1);
  l2 = strlen(s2);
  g = gcd(l1, l2);
  lcm = l1 * l2 / g;
  long long i, k;
  for (i = 0; i < g; i++) {
    k = i;
    memset(ch[i], 0, sizeof(ch[i]));
    while (k < l1) {
      ch[i][s1[k] - 'a']++;
      k += g;
    }
  }
  for (i = sum = 0; i < l2; i++) sum += lcm / l2 - ch[i % g][s2[i] - 'a'];
  printf("%I64d\n", sum * ((l1 * n) / lcm));
  return 0;
}
