#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
  return (b != 0 ? gcd<T>(b, a % b) : a);
}
const int maxn = 1000010;
int strA[maxn][26], strB[maxn][26];
char A[maxn], B[maxn];
int main() {
  int i, j, g, sz;
  long long n, m;
  cin >> n >> m;
  cin >> A >> B;
  int szA = strlen(A);
  int szB = strlen(B);
  g = gcd(szA, szB);
  for (i = 0; i < szA; i++) strA[i % g][A[i] - 'a']++;
  for (i = 0; i < szB; i++) strB[i % g][B[i] - 'a']++;
  long long matches = 0;
  for (i = 0; i < g; i++) {
    for (j = 0; j < 26; j++) matches += ((long long)strA[i][j] * strB[i][j]);
  }
  long long total = (n * szA);
  long long mul = (n / (szB / g));
  matches *= mul;
  cout << (total - matches) << endl;
  return 0;
}
