#include <bits/stdc++.h>
using namespace std;
long long n, m, gg, la, lb, lc;
long long suma[105], sumb[105];
char a[1000005], b[1000005];
long long js(char aa) {
  if ('a' <= aa && aa <= 'z') return aa - 'a';
  if ('A' <= aa && aa <= 'Z') return aa - 'A' + 26;
  return 100;
}
long long gcd(long long aa, long long bb) {
  if (aa < bb) swap(aa, bb);
  while (bb) {
    long long tt = aa % bb;
    aa = bb;
    bb = tt;
  }
  return aa;
}
int main() {
  scanf("%lld%lld", &n, &m);
  scanf("%s%s", a, b);
  la = strlen(a);
  lb = strlen(b);
  gg = gcd(la, lb);
  lc = n / (lb / gg);
  long long ans = 0;
  for (long long i = 0; i < gg; ++i) {
    memset(suma, 0, sizeof(suma));
    memset(sumb, 0, sizeof(sumb));
    long long zh = lb / gg;
    for (long long j = i; j < la; j += gg) suma[js(a[j])]++;
    for (long long j = i; j < lb; j += gg) sumb[js(b[j])]++;
    for (long long j = 0; j <= 51; ++j) ans += suma[j] * (zh - sumb[j]);
  }
  ans *= lc;
  printf("%lld", ans);
  return 0;
}
