#include <bits/stdc++.h>
using namespace std;
int sum[1000000 + 10][27];
char c1[1000000 + 10], c2[1000000 + 10];
long long n, m;
long long len1, len2;
long long gcd(long long a, long long b) {
  long long t = a;
  while (b) {
    a = b;
    b = t % b;
    t = a;
  }
  return a;
}
int main() {
  cin >> n >> m;
  scanf("%s%s", c1, c2);
  len1 = strlen(c1), len2 = strlen(c2);
  long long t = gcd(len1, len2);
  long long k = n / (len2 / t);
  long long res = 0;
  for (int i = 0; i < len2; ++i) sum[i % t][c2[i] - 'a']++;
  for (int i = 0; i < len1; ++i)
    for (int j = 0; j < 26; ++j)
      if (j != c1[i] - 'a') res += sum[i % t][j];
  res *= k;
  cout << res << endl;
  return 0;
}
