#include <bits/stdc++.h>
using namespace std;
string s, t;
long long gcd(long long a, long long b) {
  while ((a %= b) && (b %= a))
    ;
  return a + b;
}
long long c[26];
int main() {
  long long N, M, gd, lm;
  while (cin >> N >> M >> s >> t) {
    gd = gcd(s.length(), t.length());
    long long lens = s.length(), lent = t.length();
    long long tm = lent / gd;
    long long ans = 0;
    for (long long i = 0; i < gd; i++) {
      memset(c, 0, sizeof(c));
      for (long long j = 0; j < tm; j++) c[t.at((i + j * gd) % lent) - 'a']++;
      for (long long j = i; j < lens; j += gd)
        for (long long k = 0; k < 26; k++)
          if (s.at(j) - 'a' != k) ans += c[k];
    }
    lm = lens * lent / gd;
    ans *= (N * lens / lm);
    cout << ans << endl;
  }
  return 0;
}
