#include <bits/stdc++.h>
using namespace std;
unsigned long long n, i, j, m, x, y, u;
string a, b;
unsigned long long gcd(unsigned long long r1, unsigned long long r2) {
  if (r2 == 0LL)
    return r1;
  else
    return gcd(r2, r1 % r2);
};
unsigned long long lca(unsigned long long d1, unsigned long long d2) {
  return d1 * d2 / gcd(d1, d2);
};
map<char, map<int, int> > f;
unsigned long long solve() {
  unsigned long long g = gcd(x, y);
  unsigned long long cnt = 0, cnt2 = 0;
  for (i = 0; i < a.length(); i++)
    if (f[a[i]][i % g])
      cnt += f[a[i]][i % g] - 1;
    else {
      cnt2 = 0;
      for (j = i % g; j < y; j += g) cnt2 += a[i] != b[j];
      f[a[i]][i % g] = cnt2 + 1;
      cnt += cnt2;
    };
  return cnt;
};
int main() {
  cin >> n >> m;
  cin >> a >> b;
  x = a.length();
  y = b.length();
  if (x > y) swap(x, y), swap(a, b), swap(n, m);
  u = solve();
  u = u * (n * x / lca(x, y));
  cout << u << endl;
  return 0;
}
