#include <bits/stdc++.h>
using namespace std;
char a[110110], c[110110];
int b, d;
int ta, tc;
int pos[110];
int qtd[110];
int mk[110];
int mkq[110];
int su = 0;
int get(int ind, char ch) {
  int inow = ind, cnt = 0;
  while (a[inow] != ch && cnt < ta) {
    cnt++;
    inow = (inow + 1) % ta;
  }
  if (cnt == ta && a[inow] != ch) return -1;
  su = cnt;
  return inow;
}
int main() {
  scanf("%d %d", &b, &d);
  scanf("%s", a);
  scanf("%s", c);
  memset(mk, -1, sizeof mk);
  memset(mkq, -1, sizeof mkq);
  ta = strlen(a), tc = strlen(c);
  if (ta * b < tc * d)
    printf("0\n");
  else {
    bool imp = false;
    for (int i = 0; i < ta; ++i) {
      int p = i;
      for (int j = 0; j < tc; ++j) {
        int p0 = get((p) % ta, c[j]);
        qtd[i] += su + 1;
        if (p0 == -1) {
          imp = true;
          break;
        }
        p = (p0 + 1) % ta;
      }
      pos[i] = (p) % ta;
    }
    if (imp)
      printf("0\n");
    else {
      int p = 0, q = 0, qc = 0;
      int qnt = 0;
      while (mk[p] == -1 && q < ta * b) {
        mk[p] = q;
        mkq[p] = qc;
        q += qtd[p];
        p = pos[p];
        qc++;
      }
      if (q >= ta * b) {
        printf("%d\n", qc / d);
      } else {
        int tamcic = q - mk[p];
        int qccic = qc - mkq[p];
        int resp = qc + (qccic * ((ta * b - q) / tamcic));
        int inow = q + tamcic * ((ta * b - q) / tamcic);
        memset(mk, -1, sizeof mk);
        memset(mkq, -1, sizeof mkq);
        while (inow < ta * b) {
          inow += qtd[inow % ta];
          resp++;
        }
        if (inow > ta * b) resp--;
        printf("%d\n", resp / d);
      }
    }
  }
  return 0;
}
