#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 5;
int f[maxn];
char a[maxn], c[maxn];
int b, d;
int main() {
  scanf("%d%d", &b, &d);
  scanf("%s %s", a, c);
  int la = strlen(a), lc = strlen(c);
  for (int i = 0; i < lc; i++) {
    f[i] = 0;
    for (int j = 0; j < la; j++) {
      if (a[j] == c[(i + f[i]) % lc]) f[i]++;
    }
  }
  int res = 0;
  for (int i = 0; i < b; i++) {
    res += f[res % lc];
  }
  printf("%d\n", res / lc / d);
  return 0;
}
