#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
int cnt[N][30];
long long gcd(long long m, long long n) { return n ? gcd(n, m % n) : m; }
int main() {
  long long n, m;
  cin >> n >> m;
  string x, y;
  cin >> x >> y;
  long long g = gcd(x.size(), y.size());
  long long len, answer = len = x.size() / g * y.size();
  for (int i = 0; i < (x.size()); i++) {
    cnt[i % g][x[i] - 'a']++;
  }
  for (int i = 0; i < (y.size()); i++) {
    answer -= cnt[i % g][y[i] - 'a'];
  }
  cout << answer * (x.size() * n / len) << endl;
  return 0;
}
