#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e6 + 100;
int dp[maxN][40];
long long n, m;
string s, z;
int gcd(int a, int b) { return (a % b) ? gcd(b, a % b) : b; }
int main() {
  cin >> n >> m;
  cin >> s >> z;
  int d = gcd(s.size(), z.size());
  for (int(i) = (0); (i) < (int)(z.size()); ++(i)) dp[i % d][z[i] - 'a']++;
  long long cnt = 0;
  for (int(i) = (0); (i) < (int)(s.size()); ++(i))
    cnt += (n * d / z.size()) * dp[i % d][s[i] - 'a'];
  cout << (long long)(s.size() * n - cnt);
}
