#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int ma[1000005][26];
int main() {
  long long m, n, l = 0, t = 0, ans = 0, i;
  string a, b;
  int g = 0, la, lb;
  while (cin >> m >> n >> a >> b) {
    la = a.length();
    lb = b.length();
    t = la * m;
    g = gcd(la, lb);
    l = lcm(la, lb);
    ans = l;
    for (int i = 0; i < g; i++)
      for (int j = 0; j < 26; j++) ma[i][j] = 0;
    for (i = 0; i < la; i++) ma[i % g][a[i] - 'a']++;
    for (i = 0; i < lb; i++) {
      ans -= ma[i % g][b[i] - 'a'];
    }
    ans = ans * (t / l);
    cout << ans << endl;
  }
  return 0;
}
