#include <bits/stdc++.h>
using namespace std;
long long f[26][1000100];
char str1[1000100], str2[1000100];
long long a[1000100], b[1000100];
long long len1, len2, n, m;
long long gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  scanf("%I64d %I64d%c", &n, &m, &str1[0]);
  cin.getline(str1, 2000000);
  cin.getline(str2, 2000000);
  len1 = strlen(str1);
  len2 = strlen(str2);
  for (int i = 0; i < len1; i++) a[i] = str1[i] - 'a';
  for (int i = 0; i < len2; i++) b[i] = str2[i] - 'a';
  long long k = gcd(len1, len2);
  for (int i = 0; i < 26; i++)
    for (int j = 0; j < k; j++) {
      for (int h = j;;) {
        if (b[h] != i) f[i][j]++;
        h += k;
        if (h >= len2) h -= len2;
        if (h == j) break;
      }
    }
  long long ans = 0;
  for (int i = 0; i < len1; i++) ans += f[a[i]][i % k];
  ans *= n * k / len2;
  cout << ans << endl;
}
