#include <bits/stdc++.h>
using namespace std;
int b, d;
char str1[110], str2[110];
int len1, len2;
int dp[110], nex[110];
void init() {
  memset(dp, 0, sizeof(dp));
  memset(nex, 0, sizeof(nex));
}
void solve(int now) {
  int temp = now;
  int i = 0;
  int cnt = 0;
  while (i < len1) {
    if (str1[i] == str2[temp]) {
      temp++;
      i++;
    } else
      i++;
    if (temp == len2) {
      cnt++;
      temp = 0;
    }
  }
  dp[now] = cnt;
  nex[now] = temp;
}
int main() {
  int i, j;
  scanf("%d%d", &b, &d);
  scanf("%s%s", str1, str2);
  init();
  len1 = strlen(str1);
  len2 = strlen(str2);
  for (i = 0; i < len2; i++) solve(i);
  int now = 0, ans = 0;
  while (b--) {
    ans += dp[now];
    now = nex[now];
  }
  printf("%d\n", ans / d);
  return 0;
}
