#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long infLL = 0x3f3f3f3f3f3f3f3fLL;
const int hash_mod = 1000037;
const double pi = acos(-1);
const double eps = 1e-10;
const int maxl = 1000000 + 5;
long long n, m;
char a[maxl], b[maxl];
int cnt[maxl][26];
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
int main() {
  scanf("%I64d%I64d", &n, &m);
  scanf("%s%s", a, b);
  int x = strlen(a), y = strlen(b);
  int g = gcd(x, y);
  long long l = (long long)x * y / g;
  long long tot = (long long)x * n;
  long long res = 0;
  for (int i = 0; i < x; ++i) ++cnt[i % g][a[i] - 'a'];
  for (int i = 0; i < y; ++i) res += cnt[i % g][b[i] - 'a'];
  res *= tot / l;
  res = tot - res;
  printf("%I64d\n", res);
  return 0;
}
