#include <bits/stdc++.h>
using namespace std;
const int cstMax = 1e6 + 100;
const int cstAlphaSize = 26;
char a[cstMax], b[cstMax];
int c[cstMax][cstAlphaSize];
long long getGcd(long long a, long long b) {
  long long r;
  while (b != 0) r = a % b, a = b, b = r;
  return a;
}
int main() {
  long long n, m;
  long long alen, blen, gcd, lcm;
  long long cycleValue, nCicles;
  while (cin >> n >> m) {
    cin >> a >> b;
    alen = strlen(a);
    blen = strlen(b);
    gcd = getGcd(alen, blen);
    lcm = alen / gcd * blen;
    cycleValue = lcm;
    nCicles = n * alen / lcm;
    memset(c, 0, sizeof c);
    for (int i = (0); (i) < int(alen); ++i) ++c[i % gcd][int(a[i] - 'a')];
    for (int i = (0); (i) < int(blen); ++i)
      cycleValue -= c[i % gcd][int(b[i] - 'a')];
    cout << (cycleValue * nCicles) << endl;
  }
  return 0;
}
