#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T sqr(T a) {
  return a * a;
}
long long chx[30], chy[30];
long long gcd(long long a, long long b) {
  if (a == b) return a;
  if (a % 2 == 0 && b % 2 == 0) return 2 * gcd(a / 2, b / 2);
  if (a % 2 == 0) return gcd(a / 2, b);
  if (b % 2 == 0) return gcd(a, b / 2);
  if (b > a) return gcd(a, b - a);
  return gcd(a - b, b);
}
long long lcd(long long a, long long b) { return a * b / gcd(a, b); }
int main() {
  char x[(int)1e6 + 10], y[(int)1e6 + 10];
  long long n, m;
  scanf("%I64d%I64d\n", &n, &m);
  gets(x);
  gets(y);
  long long lx = strlen(x), ly = strlen(y);
  long long k = n * lx / lcd(lx, ly);
  long long r = gcd(lx, ly);
  long long ans = 0;
  for (int i = 0; i < (r); ++i) {
    for (int j = 0; j < (30); ++j) chx[j] = 0;
    for (int j = 0; j < (30); ++j) chy[j] = 0;
    for (int j = 0; j < (lx / r); ++j) chx[x[j * r + i] - 'a']++;
    for (int j = 0; j < (ly / r); ++j) chy[y[j * r + i] - 'a']++;
    for (int j = 0; j < (30); ++j) ans += chx[j] * chy[j];
  }
  ans *= k;
  printf("%I64d", n * lx - ans);
  return 0;
}
