#include <bits/stdc++.h>
using namespace std;
const int max_n = 1000009;
int cnt[max_n][26];
char s[max_n], t[max_n];
long long n, m;
long long gcd(long long x, long long y) {
  if (!y) return x;
  return gcd(y, x % y);
}
void solve() {
  long long lens = strlen(s);
  long long lent = strlen(t);
  long long gd = gcd(lens, lent);
  long long lcm = (lens * lent) / gd;
  long long beishu = (lens * n) / lcm;
  memset(cnt, 0, sizeof(cnt));
  long long ans = lcm;
  for (int i = 0; i < lens; i++) cnt[i % gd][s[i] - 'a']++;
  for (int i = 0; i < lent; i++) ans -= cnt[i % gd][t[i] - 'a'];
  cout << ans * beishu << endl;
}
int main() {
  cin >> n >> m >> s >> t;
  solve();
  return 0;
}
