#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
long long co[N][30], sum[N];
string s1, s2;
int gcd(int a, int b) {
  int t;
  while (b != 0) {
    t = b;
    b = a % b;
    a = t;
  }
  return a;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  cin >> s1 >> s2;
  int g = gcd(s1.size(), s2.size()), i, j;
  for (i = 0; i < s2.size(); i++) {
    co[i % g][s2[i] - 'a']++;
    sum[i % g]++;
  }
  long long ans = 0;
  for (i = 0; i < s1.size(); i++) {
    ans += sum[i % g] - co[i % g][s1[i] - 'a'];
  }
  long long lcm = ((long long)s1.size() * (long long)s2.size()) / g, prod;
  prod = (n * (long long)s1.size()) / lcm;
  cout << ans * prod;
}
