#include <bits/stdc++.h>
using namespace std;
long long first, second, cycle_s, cycle_len, l;
int n, m, d, cnt[2][1000005][26];
string A, B;
int gcd(int first, int second) {
  if (!second) return first;
  return gcd(second, first % second);
}
int main() {
  cin >> first >> second >> A >> B;
  n = A.size();
  m = B.size();
  d = gcd(n, m);
  int i, j;
  for (i = 0; i < n; i += d)
    for (j = 0; j < d; j++) cnt[0][j][A[i + j] - 'a']++;
  for (i = 0; i < m; i += d)
    for (j = 0; j < d; j++) cnt[1][j][B[i + j] - 'a']++;
  for (j = 0; j < d; j++)
    for (i = 0; i < 26; i++) cycle_s += (long long)cnt[0][j][i] * cnt[1][j][i];
  cycle_len = (long long)m * n / d;
  l = n * first;
  cout << l - l / cycle_len * cycle_s << "\n";
  return 0;
}
