#include <bits/stdc++.h>
const int N = 1000010;
char a[N], b[N];
long long n, m;
int cnt[26], la, lb;
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int main() {
  scanf("%lld%lld", &n, &m);
  scanf("%s", a);
  scanf("%s", b);
  la = strlen(a);
  lb = strlen(b);
  long long d = la > lb ? gcd(la, lb) : gcd(lb, la), ans = 0, del = lb / d;
  for (int i = 0; i < d; i++) {
    memset(cnt, 0, sizeof(cnt));
    for (int j = i; j < lb; j += d) ++cnt[b[j] - 'a'];
    for (int j = i; j < la; j += d) ans += del - cnt[a[j] - 'a'];
  }
  ans *= n / del;
  printf("%lld\n", ans);
  return 0;
}
