#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
string a, b;
long long n, m, count1[27][maxn], N, M;
bool kt[maxn];
int i, j;
long long gcd(long long a, long long b) {
  while (b != 0) {
    long long r = a % b;
    a = b;
    b = r;
  }
  return a;
}
int main() {
  cin >> N >> M;
  scanf("\n");
  getline(cin, a);
  getline(cin, b);
  n = a.length();
  m = b.length();
  long long bcnn = (n * m) / gcd(n, m), demn = bcnn / n, demm = bcnn / m,
            nc = gcd(n, m);
  long long solan = min(N / demn, M / demm), dun, dum;
  for (int i = 0; i <= n - 1; i++) count1[int(a[i]) - 96][i % nc]++;
  long long res = 0;
  for (int i = 0; i <= m - 1; i++)
    res += ((n / nc) - count1[int(b[i]) - 96][i % nc]);
  res = res * solan;
  dun = N - solan * demn;
  dum = M - solan * demm;
  if (dun != 0 && dum != 0) {
    memset(kt, 0, sizeof(kt));
    i = 0;
    long long xt = min(dum, dun);
    kt[i] = true;
    for (int j = 2; j <= min(dum, dun); j++) {
      i = (i + m) % n;
      kt[i] = true;
    }
    memset(count1, 0, sizeof(count1));
    for (int i = 0; i <= n - 1; i++) {
      int zz = i - (i % nc);
      if (kt[zz]) count1[int(a[i]) - 96][i % nc]++;
    }
    for (int i = 0; i <= m - 1; i++)
      res += ((xt)-count1[int(b[i]) - 96][i % nc]);
  }
  cout << res << endl;
  return 0;
}
