#include <bits/stdc++.h>
using namespace std;
long long G(long long a, long long b) {
  if (b == 0) return a;
  return G(b, a % b);
}
int cnt[1000000 + 10][30];
int main() {
  ios_base::sync_with_stdio(false);
  long long n, m, ans = 0;
  cin >> n >> m;
  string s1, s2;
  cin >> s1 >> s2;
  long long a = s1.length(), b = s2.length();
  long long gc = G(a, b);
  for (int i = 0; i < a; i++) cnt[i % gc][s1[i] - 'a']++;
  ans = a * n;
  for (int i = 0; i < s2.length(); i++) {
    ans -= (n * gc) / b * cnt[i % gc][s2[i] - 'a'];
  }
  cout << ans;
}
