#include <bits/stdc++.h>
const int MAXL = 1000001;
char x[MAXL];
char y[MAXL];
int cnt['z' + 1];
inline int gcd(int a, int b) {
  while (b != 0) {
    int t = b;
    b = a % b;
    a = t;
  }
  return a;
}
int main() {
  long long n, m;
  scanf("%I64d%I64d\n", &n, &m);
  gets(x);
  gets(y);
  int lx = strlen(x);
  int ly = n * lx / m;
  int d = gcd(lx, ly);
  long long res = 0;
  int i, j;
  for (i = 0; i < d; i++) {
    memset(cnt + 'a', 0, 26 * sizeof(int));
    for (j = i; j < lx; j += d) {
      cnt[x[j]]++;
    }
    for (j = i; j < ly; j += d) {
      res += cnt[y[j]];
    }
  }
  printf("%I64d", m * ly - res * (m / (lx / d)));
}
