#include <bits/stdc++.h>
using namespace std;
char a[1000001], b[1000001];
long long int cnt[1000001][26];
long long int gcd(long long int x, long long int y) {
  return (x % y) ? gcd(y, x % y) : y;
}
int main() {
  long long int n, m, la, lb, g, l, ans;
  cin >> n >> m;
  cin >> a >> b;
  la = strlen(a), lb = strlen(b);
  g = gcd(la, lb);
  l = la / g * lb;
  ans = l;
  for (long long int i = 0; i < lb; i++) cnt[i % g][b[i] - 'a']++;
  for (long long int i = 0; i < la; i++) ans -= cnt[i % g][a[i] - 'a'];
  cout << ans * (n * la / l) << endl;
  return 0;
}
