#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long xl, yl, g, xr, yr, ans, l[26];
char x[1000010], y[1000010];
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int main() {
  cin >> n >> m;
  scanf("%s%s", x, y);
  xl = strlen(x);
  yl = strlen(y);
  g = gcd(xl, yl);
  xr = yl / g;
  yr = xl / g;
  for (int i = 0; i < g; ++i) {
    memset(l, 0, sizeof l);
    long long st = i;
    do {
      l[x[st] - 'a']++;
      st = (st + g) % xl;
    } while (st != i);
    st = i;
    do {
      ans += xl / g - l[y[st] - 'a'];
      st = (st + g) % yl;
    } while (st != i);
  }
  ans *= n / xr;
  cout << ans << endl;
  return 0;
}
