#include <bits/stdc++.h>
using namespace std;
int B, D;
char A[1000], C[1000];
int la, lb;
int F1[1000];
int NextT[1000];
int main() {
  scanf("%d %d\n", &B, &D);
  scanf("%s\n%s\n", A, C);
  int la = strlen(A);
  int lc = strlen(C);
  for (int j = 0; j < lc; j++) {
    int t = j;
    F1[j] = 0;
    for (int i = 0; i < la; i++) {
      if (C[t] == A[i]) {
        t++;
        if (t == lc) {
          F1[j]++;
          t = 0;
        }
      }
    }
    NextT[j] = t;
  }
  long long ans = 0LL;
  int t = 0;
  for (int i = 0; i < B; i++) {
    ans += F1[t];
    t = NextT[t];
  }
  cout << ans / D << endl;
  return 0;
}
