#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) {
  long long c;
  while (b) {
    c = a % b;
    a = b;
    b = c;
  }
  return a;
}
int main() {
  long long N, M, temp;
  scanf("%I64i %I64i\n", &N, &M);
  static char as[1000005];
  static char bs[1000005];
  static char* a;
  static char* b;
  scanf("%s\n", as);
  scanf("%s\n", bs);
  long long ac = (long long)(strlen(as));
  long long bc = (long long)(strlen(bs));
  long long P = GCD(ac, bc);
  static int cnt[1000005][26];
  memset(cnt, 0, sizeof(cnt));
  if (ac >= bc) {
    a = as;
    b = bs;
  } else {
    a = bs;
    b = as;
    temp = N;
    N = M;
    M = temp;
    temp = ac;
    ac = bc;
    bc = temp;
  }
  long long i;
  for (i = 0; i < ac; i++) {
    cnt[i % P][a[i] - 'a']++;
  }
  long long res = 0LL;
  for (i = 0; i < bc; i++) {
    res += (long long)(cnt[i % P][b[i] - 'a']);
  }
  long long dist = (ac * bc) / P;
  long long total = N * ac;
  res *= (total / dist);
  printf("%I64i\n", total - res);
  return 0;
}
