#include <bits/stdc++.h>
const int size = 1000005;
char strA[size];
char strB[size];
long long m, n;
long long gcd(long long a, long long b) { return 0 == b ? a : gcd(b, a % b); }
int main() {
  scanf("%I64d %I64d", &m, &n);
  scanf("%s", strA);
  scanf("%s", strB);
  long long la = strlen(strA);
  long long lb = strlen(strB);
  long long g = gcd(la, lb);
  long long lcm = la * lb / g;
  long long ans = lcm;
  int** count = new int*[g];
  for (int i = 0; i < g; ++i) {
    count[i] = new int[26];
    for (int j = 0; j < 26; ++j) count[i][j] = 0;
  }
  for (int i = 0; i < la; ++i) count[i % g][strA[i] - 'a']++;
  for (int i = 0; i < lb; ++i) ans -= count[i % g][strB[i] - 'a'];
  printf("%I64d\n", (m * la / lcm) * ans);
  for (int i = 0; i < g; ++i) delete count[i];
  delete count;
  return 0;
}
