#include <bits/stdc++.h>
using namespace std;
int dp[1000000] = {0};
int main() {
  int b, d;
  scanf("%d%d", &b, &d);
  char a[105], c[105];
  scanf("%s", a);
  ;
  scanf("%s", c);
  ;
  int len1 = strlen(a), len2 = strlen(c);
  int vis[1000000];
  memset(vis, -1, sizeof(int) * 1000000);
  for (int i = 0; i < len2; i++) {
    int flag = 0;
    for (int j = 0; j <= len1; j++) {
      if (c[i] == a[j]) {
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      printf("0\n");
      return 0;
    }
  }
  int ind2 = 0, count2 = 0, count1 = 0, ini2 = 0, ini1 = 0;
  int cycle1 = 0, cycle2 = 0;
  int stind = 0, stcycle1 = 0, stcycle2 = 0;
  vis[0] = 0;
  while (1) {
    for (int i = 0; i < len1; i++) {
      if (c[ind2] == a[i]) ind2++;
      if (ind2 >= len2) count2++;
      ind2 %= len2;
    }
    count1++;
    if (vis[ind2] != -1) {
      stind = ind2;
      stcycle1 = vis[ind2];
      stcycle2 = dp[vis[ind2]];
      cycle1 = count1 - vis[ind2];
      cycle2 = count2 - dp[vis[ind2]];
      break;
    }
    vis[ind2] = count1;
    dp[count1] = count2;
  }
  if (b < stcycle1) {
    int rep = dp[b];
    printf("%d\n", rep / d);
    return 0;
  }
  b -= stcycle1;
  int rep = stcycle2;
  int div = b / cycle1;
  b -= div * cycle1;
  rep += cycle2 * div;
  for (int i = 0; i < b; i++) {
    for (int j = 0; j < len1; j++) {
      if (c[ind2] == a[j]) ind2++;
      if (ind2 >= len2) rep++;
      ind2 %= len2;
    }
  }
  printf("%d\n", rep / d);
  return 0;
}
