#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N = 1000010;
const double eps = 1e-8;
const long long Mod = 1000000007;
char x[N], y[N];
int cnt[N][27];
int vis[N];
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  long long n, m;
  scanf("%I64d%I64d", &n, &m);
  scanf("%s%s", x, y);
  long long la, lb;
  la = strlen(x);
  lb = strlen(y);
  long long g = gcd(la, lb);
  long long ans = n / (lb / g), res = 0;
  n = lb / g;
  m = la / g;
  memset(vis, -1, sizeof(vis));
  for (int i = 0; i < lb; i++)
    if (vis[i] == -1) {
      for (int j = i; vis[j] == -1; j = (j + la) % lb) {
        int k = y[j] - 'a';
        cnt[i][k]++;
        vis[j] = i;
      }
    }
  for (int i = 0; i < la; i++) {
    int k = x[i] - 'a';
    res += n - cnt[vis[i % lb]][k];
  }
  cout << ans * res << endl;
  return 0;
}
