#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
long long n, m;
char first[N], second[N];
int lenx, leny;
int cnt[N][26];
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  while (b != 0) {
    long long r = a % b;
    a = b;
    b = r;
  }
  return a;
}
int main() {
  cin >> n >> m;
  scanf(" %s %s", first, second);
  lenx = strlen(first);
  leny = strlen(second);
  if (lenx > leny) {
    swap(n, m);
    for (int i = 0; i < lenx; i++) swap(first[i], second[i]);
    swap(lenx, leny);
  }
  long long G = gcd(lenx, leny);
  long long L = lenx * 1LL * leny / G;
  for (int i = 0; i < leny; i++) {
    cnt[i % G][second[i] - 'a']++;
  }
  long long ans = 0LL;
  for (int i = 0; i < lenx; i++) {
    ans += cnt[i % G][first[i] - 'a'];
  }
  ans = n * 1LL * lenx - ans * (lenx * 1LL * n / L);
  cout << ans << endl;
  return 0;
}
