#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000111;
const int MOD = 1000000007;
const int S_N = 100010;
template <typename A, typename B>
ostream& operator<<(ostream& out, pair<A, B>& p) {
  cout << "(" << p.first << "," << p.second << ") ";
}
template <typename A, typename B>
void printP(const pair<A, B>& p, const char* str = NULL) {
  if (str != NULL) cout << str << ":";
  cout << "(" << p.first << "," << p.second << ") ";
}
template <typename T>
void printV(const vector<T>& v, const char* str = NULL) {
  if (str != NULL) cout << str << ": ";
  for (int i = 0; i < (v.size()); ++i) cout << v[i] << " ";
  cout << endl;
}
long long nwd(long long a, long long b) {
  if (b == 0) return a;
  return nwd(b, a % b);
}
long long nww(long long a, long long b) { return (a / nwd(a, b)) * b; }
int main() {
  ios_base::sync_with_stdio(false);
  long long n, m;
  cin >> n >> m;
  string x, y;
  cin >> x >> y;
  int lx = x.size(), ly = y.size();
  long long g = nwd(lx, ly);
  long long nw = nww(lx, ly);
  vector<vector<int> > C(g, vector<int>(26, 0));
  for (int i = 0; i < (ly); ++i) C[i % g][y[i] - 'a']++;
  long long cnt = 0;
  for (int i = 0; i < (lx); ++i) cnt += C[i % g][x[i] - 'a'];
  cout << (nw - cnt) * (n * lx / nw) << endl;
  return 0;
}
