#include <bits/stdc++.h>
using namespace std;
long long Mod[26][1000005];
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  long long n, m, a, b;
  string x, y;
  cin >> n >> m;
  cin >> x >> y;
  a = x.length();
  b = y.length();
  long long g = gcd(a, b);
  for (int i = 0; i < b; i++) Mod[y[i] - 'a'][i % g]++;
  long long kmm = a * b / g;
  long long ans = kmm;
  for (int i = 0; i < a; i++) ans -= Mod[x[i] - 'a'][i % g];
  cout << n * a / kmm * ans << endl;
  return 0;
}
