#include <bits/stdc++.h>
using namespace std;
long long n, m;
string x, y;
long long vis[1000100][26];
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int main(int argc, const char* argv[]) {
  cin >> n >> m >> x >> y;
  if (x.length() < y.length()) {
    swap(x, y);
    swap(n, m);
  }
  long long lenx = x.length();
  long long leny = y.length();
  long long len = lenx * n;
  long long g = gcd(lenx, leny);
  long long lcm = lenx * leny / g;
  long long con = len / lcm;
  long long conSame = 0;
  for (int i = 0; i < lenx; ++i) {
    vis[i % g][x[i] - 'a']++;
  }
  for (int i = 0; i < leny; ++i) {
    conSame += vis[i % g][y[i] - 'a'];
  }
  cout << (lcm - conSame) * con << endl;
  ;
  return 0;
}
