#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  if (a % b == 0) return b;
  return gcd(b, a % b);
}
long long dp[1000000 + 10][30];
int main() {
  ios_base::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  string x, y;
  cin >> x >> y;
  long long g = gcd(x.size(), y.size());
  long long first = x.size() / g * y.size();
  for (long long i = 0; i < y.size(); i++) {
    int k = i % g;
    k += g;
    k %= g;
    dp[k][y[i] - 'a']++;
  }
  long long sum = first;
  for (long long i = 0; i < x.size(); i++) {
    int k = i % g;
    k += g;
    k %= g;
    sum -= dp[k][x[i] - 'a'];
  }
  cout << sum * (n * x.size() / first);
}
