#include <bits/stdc++.h>
using namespace std;
namespace io {
const int SIZE = (1 << 21) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c,
                                       qu[55];
int f, qr;
inline void flush() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
}
inline void putc(char x) {
  *oS++ = x;
  if (oS == oT) flush();
}
template <class I>
inline void read(I &x) {
  for (f = 1, c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                              (iS == iT ? EOF : *iS++))
                            : *iS++);
       c < '0' || c > '9';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    if (c == '-') f = -1;
  for (x = 0; c <= '9' && c >= '0';
       c = (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    x = x * 10 + (c & 15);
  x *= f;
}
template <class I>
inline void print(I x) {
  if (!x) putc('0');
  if (x < 0) putc('-'), x = -x;
  while (x) qu[++qr] = x % 10 + '0', x /= 10;
  while (qr) putc(qu[qr--]);
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_flusher_;
}  // namespace io
using io ::print;
using io ::putc;
using io ::read;
const int V = 1000100;
char s[V], t[V];
int gcd(int x, int y) {
  if (!y) return x;
  return gcd(y, x % y);
}
long long int n, m;
int ct[V][26];
int main() {
  cin >> n >> m;
  scanf("%s%s", s, t);
  int ls = strlen(s), lt = strlen(t);
  int gd = gcd(ls, lt);
  long long int cp = n * ls / ((long long int)ls / gd * lt);
  memset(ct, 0, sizeof(ct));
  for (int i = 0; i < lt; i++) ct[i % gd][t[i] - 'a']++;
  long long int ret = (long long int)ls / gd * lt;
  for (int i = 0; i < ls; i++) ret -= ct[i % gd][s[i] - 'a'];
  cout << ret * cp << endl;
  return 0;
}
