#include <bits/stdc++.h>
using namespace std;
long long n, m;
int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
int main() {
  cin >> n >> m;
  string x, y;
  cin.ignore();
  getline(cin, x);
  getline(cin, y);
  int lenx = (int)x.length(), leny = (int)y.length();
  int g = gcd(lenx, leny);
  long long lcm = (long long)lenx * leny / g;
  long long ans = lcm;
  int **o = new int *[26];
  for (int i = 0; i < 26; ++i) {
    o[i] = new int[g];
  }
  for (int i = 0; i < 26; ++i)
    for (int j = 0; j < g; ++j) o[i][j] = 0;
  for (int i = 0; i < leny; ++i) {
    o[y[i] - 'a'][i % g]++;
  }
  for (int i = 0; i < lenx; ++i) {
    ans -= (long long)o[x[i] - 'a'][i % g];
  }
  for (int i = 0; i < 26; ++i) delete[] o[i];
  delete[] o;
  cout << (n * lenx) / lcm * ans;
  return 0;
}
