#include <bits/stdc++.h>
using namespace std;
long long n, m;
char A[1020304], B[1020304];
int data[1020304][27], vis[1020304];
int main() {
  cin >> n >> m;
  scanf("%s%s", A + 1, B + 1);
  int la = strlen(A + 1), lb = strlen(B + 1);
  memset(vis, 0, sizeof(vis));
  int len = 0;
  int Tot = 0;
  for (int i = 1; i <= lb; ++i)
    if (!vis[i]) {
      ++Tot;
      vis[i] = Tot;
      memset(data[Tot], 0, sizeof(data[Tot]));
      ++data[Tot][B[i] - 'a'];
      len = 1;
      for (int z = (i - 1 + la) % lb + 1; !vis[z]; z = (z - 1 + la) % lb + 1) {
        vis[z] = Tot;
        ++data[Tot][B[z] - 'a'];
        ++len;
      }
    }
  long long ans = 0;
  for (int i = 1; i <= la; ++i) {
    for (int j = 0; j <= 25; ++j)
      if ('a' + j != A[i]) {
        long long pos = (i - 1 + lb) % lb + 1;
        ans += (long long)data[vis[pos]][j] * n / len;
      }
  }
  cout << ans << endl;
  return 0;
}
