#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long n, m;
int first, second;
string s, t;
int cnt[1024 * 1024][32];
int main() {
  cin >> n >> m;
  cin >> s >> t;
  first = (int)(s.size()), second = (int)(t.size());
  int d = gcd(first, second);
  for (int i = 0; i < second; i += 1) {
    cnt[i % d][t[i] - 'a']++;
  }
  long long ret = 0;
  for (int i = 0; i < first; i += 1) {
    ret += cnt[i % d][s[i] - 'a'];
  }
  cout << (n * (long long)first) - (ret * (n / ((long long)(second / d))))
       << '\n';
  return 0;
}
