#include <bits/stdc++.h>
using namespace std;
const int N = 1000009;
char s1[N], s2[N];
long long x, y, gcd, n, m, d[N][30], lcm, times, ans, answer, cnt;
long long GCD(long long a, long long b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
int main() {
  cin >> x >> y;
  scanf(" ");
  gets(s1);
  gets(s2);
  n = strlen(s1);
  m = strlen(s2);
  gcd = GCD(n, m);
  cnt = m / gcd;
  lcm = n * m / gcd;
  times = x * n / lcm;
  for (int i = 0; i < m; ++i) ++d[i % gcd][s2[i] - 'a'];
  for (int i = 0; i < n; ++i) {
    ans = cnt - d[i % gcd][s1[i] - 'a'];
    answer += ans;
  }
  answer *= times;
  cout << answer << "\n";
  return 0;
}
