#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a > b) swap(a, b);
  if (a == 0) return b;
  return gcd(b % a, a);
}
int main() {
  cin.sync_with_stdio(0);
  long long N, M;
  cin >> N >> M;
  string x, y;
  cin >> x >> y;
  long long d = gcd(x.length(), y.length());
  int L = x.length(), K = y.length();
  long long ans = L * N;
  vector<long long> pocX(26, 0);
  vector<long long> pocY(26, 0);
  long long h = 0;
  for (int i = 0; i < d; i++) {
    int a = i;
    while (a < L) {
      pocX[x[a] - 'a']++;
      a += d;
    }
    a = i;
    while (a < K) {
      pocY[y[a] - 'a']++;
      a += d;
    }
    a = i;
    while (a < L) {
      h += pocX[x[a] - 'a'] * pocY[x[a] - 'a'];
      pocX[x[a] - 'a'] = 0;
      a += d;
    }
    a = i;
    while (a < K) {
      pocY[y[a] - 'a'] = 0;
      a += d;
    }
  }
  long long rep = N / (K / d);
  cout << ans - h * rep << "\n";
  return 0;
}
