#include <bits/stdc++.h>
using namespace std;
int nxt[110], cnt[110];
char s1[110], s2[110];
int main() {
  int i, j, k, b, d;
  while (scanf("%d%d", &b, &d) != EOF) {
    scanf("%s%s", s1, s2);
    int n1 = strlen(s1);
    int n2 = strlen(s2);
    for (i = 0; i < n2; i++) {
      int x = i, ct = 0;
      for (j = 0; j < n1; j++) {
        if (s1[j] == s2[x]) {
          x++;
          if (x == n2) {
            ct++;
            x = 0;
          }
        }
      }
      nxt[i] = x;
      cnt[i] = ct;
    }
    long long ans = 0;
    int now = 0;
    for (i = 0; i < b; i++) {
      ans += cnt[now];
      now = nxt[now];
    }
    cout << ans / d << endl;
  }
  return 0;
}
