#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  while (a) b %= a, swap(a, b);
  return b;
}
char x[1000005], y[1000005];
int aux[1000005][26];
int main() {
  long long n, m;
  cin >> n >> m;
  scanf("%s %s", x, y);
  int lenx = strlen(x), leny = strlen(y);
  long long mdc = gcd(lenx, leny);
  long long mmc = lenx / mdc * leny;
  long long diff = mmc;
  for (int i = (0); i < (leny); ++i) ++aux[i % mdc][y[i] - 'a'];
  for (int i = (0); i < (lenx); ++i) diff -= aux[i % mdc][x[i] - 'a'];
  cout << diff * (n * lenx / mmc) << endl;
  return 0;
}
