#include <bits/stdc++.h>
const int N = 1000005;
const int inf = 1 << 28;
const double eps = 1e-8;
using namespace std;
long long n, m;
char x[N], y[N];
int fuck[N][30], num[30];
int nx[N];
int lenx, leny;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
void dfs(int k) {
  nx[k] = 1;
  num[x[k] - 'a']++;
  int t = (k + leny) % lenx;
  if (!nx[t]) dfs(t);
  for (int i = 0; i < 26; i++) fuck[k][i] = num[i];
}
int main() {
  while (scanf("%I64d%I64d%s%s", &n, &m, x, y) > 0) {
    lenx = strlen(x), leny = strlen(y);
    memset(nx, 0, sizeof(nx));
    for (int i = 0; i < lenx; i++) {
      if (nx[i]) continue;
      memset(num, 0, sizeof(num));
      dfs(i);
    }
    long long res = 0;
    for (int i = 0; i < leny; i++) {
      res += fuck[i % lenx][y[i] - 'a'];
    }
    long long cir = (long long)lenx / gcd(lenx, leny) * leny;
    res *= (long long)n * lenx / cir;
    res = (long long)n * lenx - res;
    cout << res << endl;
  }
  return 0;
}
