#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int inf = 10000000;
char a[105], c[105];
int ca[26], cc[105];
int res[105];
int resn[105];
int an, cn, b, d;
int solve(int i) {
  int j = 0;
  int ans = 0;
  while (j < cn) {
    if (a[i] == c[j])
      i++, j++;
    else
      i++;
    if (i == an) i = 0;
    ans++;
  }
  return ans;
}
int main() {
  scanf("%d%d", &b, &d);
  scanf("%s", a);
  scanf("%s", c);
  an = strlen(a);
  cn = strlen(c);
  for (int i = 0; i < (an); i++) ca[a[i] - 'a']++;
  for (int i = 0; i < (cn); i++) cc[c[i] - 'a']++;
  for (int i = 0; i < (26); i++) {
    if (ca[i] * b < cc[i] * d) return puts("0") & 0;
  }
  memset((res), (-1), sizeof(res));
  memset((resn), (0), sizeof(resn));
  int pos = 0, t;
  long long sum = 0;
  int cd = 0;
  long long len = an * b;
  int cyclelen, cycled, st;
  while (1) {
    t = solve(pos);
    res[pos] = sum;
    sum += t;
    if (sum > len) break;
    resn[pos] = cd++;
    pos = (pos + t) % an;
    if (res[pos] != -1) {
      cyclelen = sum - res[pos];
      cycled = cd - resn[pos];
      break;
    }
  }
  len -= sum;
  if (len > 0) {
    cd += (cycled * (len / cyclelen));
    len %= cyclelen;
    sum = 0;
    while (1) {
      t = solve(pos);
      sum += t;
      if (sum > len) break;
      cd++;
      pos = (pos + t) % an;
    }
  }
  int ans = cd / d;
  cout << ans << endl;
  return 0;
}
