#include <bits/stdc++.h>
using namespace std;
const long long MOD = -1;
long long ans;
long long dp[1000001][27];
int gcd(int l, int r) {
  if (!l) return r;
  return gcd(r % l, l);
}
int main() {
  long long n, m, cycleLength, g, kol, asize, bsize;
  string a, b;
  cin >> n >> m;
  cin >> a >> b;
  asize = a.size();
  bsize = b.size();
  g = gcd(asize, bsize);
  cycleLength = bsize * asize / g;
  kol = asize * n;
  for (int i = 0; i < bsize; i++) dp[i % g][b[i] - 'a']++;
  for (int i = 0; i < asize; i++) ans += dp[i % g][a[i] - 'a'];
  cerr << cycleLength << " " << g << " ,  ans = " << ans << endl;
  ans = kol - ans * (kol / cycleLength);
  cout << ans << endl;
}
