#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000500;
long long gcd(long long a, long long b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
long long a, b;
int n, m;
char s[maxn], t[maxn];
int cs[200], ct[200];
void scan() {
  cin >> a >> b >> s >> t;
  n = strlen(s);
  m = strlen(t);
}
long long solve(const string& s, const string& t) {
  for (int i = 0; i < (int)(26); i++) cs[i] = ct[i] = 0;
  for (int i = 0; i < (int)(s.length()); i++) ++cs[s[i] - 'a'];
  long long res = 0;
  for (int i = 0; i < (int)(t.length()); i++) {
    res += s.length() - cs[t[i] - 'a'];
  }
  return res;
}
void solve() {
  long long res = 0;
  int g = gcd(n, m);
  for (int i = 0; i < (int)(g); i++) {
    string ns, nt;
    for (int j = i; j < n; j += g) ns += s[j];
    for (int j = i; j < m; j += g) nt += t[j];
    res += solve(ns, nt);
  }
  cout << res * gcd(a, b) << endl;
}
int main() {
  scan();
  solve();
  return 0;
}
