#include <bits/stdc++.h>
using namespace std;
char buf[1000009];
string a, b;
int cnt[1000009][26];
void readString(string &s) {
  scanf("%s", buf);
  s = buf;
}
int gcd(int a, int b) {
  while (b > 0) {
    int t = a % b;
    a = b;
    b = t;
  }
  return a;
}
int main() {
  long long N, M;
  int i;
  cin >> N >> M;
  scanf("\n");
  readString(a);
  readString(b);
  int g = gcd(a.size(), b.size());
  for (i = 0; i < a.size(); i++) {
    cnt[i % g][a[i] - 'a']++;
  }
  long long common = 0;
  for (i = 0; i < b.size(); i++) common += cnt[i % g][b[i] - 'a'];
  long long len = (long long)(a.size()) * b.size() / (long long)(g);
  long long _c = common * (M * (long long)(b.size()) / len);
  cout << (long long)(b.size()) * M - _c << endl;
}
