#include <bits/stdc++.h>
using namespace std;
const int N = 1000006;
bool vis[N];
long long n, m, sum[N][26], la, lb, t[26];
char x[N], y[N];
int main() {
  cin >> n >> m;
  scanf("%s%s", x, y);
  la = strlen(x);
  lb = strlen(y);
  for (int i = 0; i < lb; i++) {
    if (vis[i]) continue;
    int j = i, sz = 0;
    memset(t, 0, sizeof(t));
    for (int k = 0;; k++) {
      sz++;
      t[y[j] - 'a']++;
      j = (j + la) % lb;
      if (j == i) break;
    }
    long long p = n % sz, q = n / sz;
    for (int j = 0; j < 26; j++) t[j] *= q;
    j = i;
    for (int k = 0; k < p; k++) {
      t[y[j] - 'a']++;
      j = (j + la) % lb;
    }
    p = j;
    j = i;
    for (int k = 0; k < sz; k++) {
      for (int l = 0; l < 26; l++) sum[j][l] = t[l];
      vis[j] = 1;
      t[y[j] - 'a'] -= 1;
      t[y[p] - 'a'] += 1;
      p = (p + la) % lb;
      j = (j + la) % lb;
    }
  }
  long long ans = 0;
  for (int i = 0; i < la; i++) {
    int p = i % lb;
    for (int j = 0; j < 26; j++) {
      if (x[i] - 'a' != j) ans += sum[p][j];
    }
  }
  cout << ans << endl;
  return 0;
}
