#include <bits/stdc++.h>
using namespace std;
const int N = 200;
char a[N], c[N];
int cnt[N], nxt[N];
int b, d;
int main(void) {
  scanf("%d%d", &b, &d);
  scanf("%s%s", a, c);
  int len_a = strlen(a);
  int len_c = strlen(c);
  for (int i = 0; i < len_c; i++) {
    int now = i;
    for (int j = 0; j < len_a; j++) {
      if (c[now] == a[j]) {
        now++;
        if (now >= len_c) {
          ++cnt[i];
          now = 0;
        }
      }
    }
    nxt[i] = now;
  }
  int sum = 0;
  for (int i = 0, now = 0; i < b; i++, now = nxt[now]) sum += cnt[now];
  printf("%d\n", sum / d);
  return 0;
}
