#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
long long n, m;
char s[N], t[N];
long long counts[N][30] = {0};
long long get_gcd(long long x, long long y) {
  if (!y) return x;
  return get_gcd(y, x % y);
}
int main() {
  scanf("%I64d %I64d", &n, &m);
  scanf("%s %s", s, t);
  long long l1 = strlen(s), l2 = strlen(t);
  long long gcd = get_gcd(l1, l2);
  long long temp1 = l1, temp2 = l2;
  temp2 /= gcd;
  long long temp = temp1 * temp2;
  for (long long i = 0; i < l1; i++) {
    counts[i % gcd][s[i] - 'a']++;
  }
  long long ans = temp;
  for (long long i = 0; i < l2; i++) {
    ans -= counts[i % gcd][t[i] - 'a'];
  }
  long long ret = l1 * n / temp;
  ans = ans * ret;
  cout << ans << endl;
  return 0;
}
