#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long la, lb, lc;
char a[1000005];
char b[1000005];
int Ac[1000005][27];
int Bc[1000005][27];
long long gcd(long long a, long long b) {
  while (b) {
    long long r = a % b;
    a = b;
    b = r;
  }
  return a;
}
int main() {
  cin >> n >> m;
  cin >> a;
  cin >> b;
  for (la = 0; a[la]; la++)
    ;
  for (lb = 0; b[lb]; lb++)
    ;
  lc = gcd(la, lb);
  long long ans = 0;
  for (int i = 0; i < la; i++) Ac[i % lc][a[i] - 'a']++;
  for (int i = 0; i < lb; i++) Bc[i % lc][b[i] - 'a']++;
  for (int i = 0; i < lc; i++)
    for (int j = 0; j < 26; j++)
      ans -= 1LL * Ac[i][j] * Bc[i][j] * (n * lc / lb);
  ans += n * la;
  cout << ans;
}
