#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (max(a, b) % min(a, b) == 0) return min(a, b);
  return gcd(max(a, b) % min(a, b), min(a, b));
}
int main() {
  long long int n, m;
  cin >> n >> m;
  string s1, s2;
  cin >> s1 >> s2;
  long long int l1 = s1.length(), l2 = s2.length();
  long long int g = gcd(l1, l2);
  long long int dp[g + 1][27];
  for (int i = 0; i <= g; i++)
    for (int j = 0; j <= 26; j++) dp[i][j] = 0;
  long long int l = l1 * l2 / g;
  long long int ans = l;
  for (int i = 0; i <= l1 - 1; i++) dp[i % g][s1[i] - 'a']++;
  for (int i = 0; i <= l2 - 1; i++) ans -= dp[i % g][s2[i] - 'a'];
  ans = ((n * l1) / l) * ans;
  cout << ans;
  return 0;
}
