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