#include <bits/stdc++.h>
using namespace std;
char a[1000], c[1000];
int main() {
  int b, d, f[1000], nex[1000];
  while (scanf("%d%d", &b, &d) != EOF) {
    memset(f, 0, sizeof f);
    memset(nex, 0, sizeof nex);
    scanf("%s", a);
    int na = strlen(a);
    scanf("%s", c);
    int nc = strlen(c);
    for (int j = 0; j < nc; j++) {
      nex[j] = j;
      for (int i = 0; i < na; i++) {
        if (c[nex[j]] == a[i]) {
          if (nex[j] + 1 == nc) {
            f[j]++;
            nex[j] = 0;
          } else
            nex[j]++;
        }
      }
    }
    int x = 0, ans = 0;
    while (b--) {
      ans += f[x];
      x = nex[x];
    }
    printf("%d\n", ans / d);
  }
  return 0;
}
