#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (a < b) return gcd(b, a);
  if (b == 0) return a;
  return gcd(b, a % b);
}
char s[1000006], t[1000006];
int c[1000006][30];
int main() {
  long long int a, b, ans, l1, l2, g, lcm, i, n, m, x;
  ans = 0;
  cin >> n >> m;
  cin >> s >> t;
  l1 = strlen(s);
  l2 = strlen(t);
  lcm = (l1 * l2) / gcd(l1, l2);
  g = gcd(l1, l2);
  x = lcm / l1;
  for (i = 0; i < l2; i++) c[i % g][t[i] - 'a']++;
  for (i = 0; i < l1; i++) {
    ans += (x - c[i % g][s[i] - 'a']);
  }
  ans *= (n / x);
  cout << ans << endl;
  return 0;
}
