#include <bits/stdc++.h>
using namespace std;
const int iinf = 0x3f3f3f3f;
const long long linf = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6;
long long a, b, ns;
int n, m, g, cnt[N][26], sum[N];
string sn, sm;
int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> a >> b >> sn >> sm, n = int((sn).size()), m = int((sm).size()),
                             g = gcd(n, m);
  for (int i(0); i < (n); ++i) cnt[i % g][sn[i] - 'a']++, sum[i % g]++;
  for (int i(0); i < (m); ++i) ns += sum[i % g] - cnt[i % g][sm[i] - 'a'];
  ns *= a / (m / g);
  cout << ns << '\n';
  return 0;
}
