#include <bits/stdc++.h>
using namespace std;
unsigned long long gcd(unsigned long long a, unsigned long long b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a + b;
}
unsigned long long lcd(unsigned long long a, unsigned long long b) {
  return ((a * 1ull) / gcd(a, b)) * b;
}
int main(void) {
  unsigned long long n, m;
  cin >> n >> m;
  string a, b;
  cin >> a >> b;
  unsigned long long g = gcd(a.size(), b.size()), l = lcd(a.size(), b.size());
  map<unsigned long long, map<char, unsigned long long> > c;
  for (int i = 0; i < b.size(); ++i) ++c[i % g][b[i]];
  unsigned long long ans = l;
  for (int i = 0; i < a.size(); ++i) {
    ans -= c[i % g][a[i]];
  }
  cout << n * a.size() / l * ans;
  return 0;
}
