#include <bits/stdc++.h>
using namespace std;
int dp[110], ans, lbei, lju, num[110];
char bei[110], ju[110];
int main() {
  int b, d, j;
  while (scanf("%d%d", &b, &d) != EOF) {
    scanf("%s%s", &bei, &ju);
    lbei = strlen(bei);
    lju = strlen(ju);
    memset(num, 0, sizeof num);
    ans = 0;
    for (j = 0; j < lju; j++) {
      int j1 = j;
      for (int i = 0; i < lbei; i++) {
        if (bei[i] == ju[j]) j++;
        if (j == lju) {
          num[j1]++;
          j = 0;
        }
      }
      dp[j1] = j - 1;
      j = j1;
    }
    j = 0;
    for (int i = 1; i <= b; i++) {
      ans += num[j];
      j = dp[j] + 1;
    }
    ans /= d;
    printf("%d\n", ans);
  }
}
