#include <bits/stdc++.h>
char str1[200], str2[200];
char lenstr1, lenstr2;
int dp1[200];
int dp2[200];
int got[200] = {0};
int twice;
int twicep;
int countc;
int calel(int st) {
  int ite = st;
  int len = 1;
  for (int i = 0; i < lenstr2; i++) {
    int flag = 0;
    while (str1[st] != str2[i]) {
      st++;
      if (st == lenstr1) {
        len++;
        st = 0;
        if (flag) return 1;
        flag = 1;
      }
    }
    st++;
    if (st == lenstr1) {
      len++;
      st = 0;
    }
  }
  dp1[ite] = len;
  dp2[ite] = st;
  return 0;
}
int main() {
  int s1, s2;
  scanf("%d%d", &s1, &s2);
  scanf("%s%s", str1, str2);
  lenstr1 = strlen(str1);
  lenstr2 = strlen(str2);
  for (int i = 0; i < lenstr1; i++)
    if (calel(i)) {
      printf("0\n");
      return 0;
    }
  got[0] = 1;
  for (int i = 0;;) {
    int j = dp2[i];
    if (got[j]) {
      twice = got[i] + dp1[i] - 1;
      twicep = j;
      break;
    }
    got[j] = got[i] + dp1[i] - 1;
    i = j;
  }
  if (twice >= s1) {
    countc = 0;
    int i, j;
    for (i = 0, j = 1; j <= s1;) {
      j += dp1[i] - 1;
      i = dp2[i];
      countc++;
    }
    if (i == 0 && countc != 1) countc++;
  } else {
    countc = 0;
    int p1 = 1;
    for (int i = 0; i != twicep;) {
      p1 += dp1[i] - 1;
      i = dp2[i];
      countc++;
    }
    int left = s1 - p1;
    int i = twicep;
    int single = 0;
    do {
      i = dp2[i];
      single++;
    } while (i != twicep);
    int sinlen = twice - p1;
    countc += single * (left / sinlen);
    int p2 = p1 + left / sinlen * sinlen;
    for (i = twicep;;) {
      p2 += dp1[i] - 1;
      i = dp2[i];
      if (p2 > s1) break;
      countc++;
    }
    if (i == 0) countc++;
  }
  printf("%d\n", countc / s2);
  return 0;
}
