#include <bits/stdc++.h>
using namespace std;
const int NR = 110;
long long cnt[NR], nxt[NR];
long long b, d, lena, lenc, ans;
char a[NR], c[NR];
int main() {
  scanf("%lld%lld%s%s", &b, &d, a, c);
  lena = strlen(a);
  lenc = strlen(c);
  for (int i = 0, x; i < lenc; i++) {
    x = i;
    for (int j = 0; j < lena; j++)
      if (a[j] == c[x]) {
        x++;
        if (x == lenc) cnt[i]++, x = 0;
      }
    nxt[i] = x;
  }
  int pos = 0;
  for (int i = 1; i <= b; i++) {
    ans += cnt[pos];
    pos = nxt[pos];
  }
  printf("%lld\n", ans / d);
  return 0;
}
