#include <bits/stdc++.h>
using namespace std;
long long nD, mD, len;
string s1, s2;
long long n, m, ans;
int g1[1000020][30], g2[1000020][30];
long long gcd(long long n, long long m) {
  while (n && m) {
    if (n > m)
      n %= m;
    else
      m %= n;
  }
  return (n + m);
}
long long lcm(long long n, long long m) { return (n / gcd(n, m)) * m; }
int main() {
  ios ::sync_with_stdio(false);
  cin >> nD >> mD;
  cin >> s1 >> s2;
  n = s1.size();
  m = s2.size();
  long long len = nD * (long long)n;
  long long g = gcd(n, m);
  for (int i = 0; i < n; ++i) g1[i % g][s1[i] - 'a']++;
  for (int i = 0; i < m; ++i) ans += g1[i % g][s2[i] - 'a'];
  long long d = lcm(n, m);
  ans = ans * (len / d);
  cout << len - ans << endl;
}
