#include <bits/stdc++.h>
using namespace std;
int dp[222][105];
int dp2[105];
char cc[555];
char c[111];
char a[111];
int alen, clen;
int main() {
  int b, d;
  scanf("%d %d\n", &b, &d);
  gets(a);
  gets(c);
  alen = strlen(a);
  clen = strlen(c);
  for (int i = 0; i < clen; i++) {
    cc[i] = cc[i + clen] = c[i];
  }
  for (int i = 0; i < clen; i++) {
    int p = i;
    for (int j = 0; j < alen; j++) {
      if (a[j] == c[p]) {
        p++;
        dp2[i]++;
      }
      if (p == clen) p = 0;
    }
  }
  int len = 0;
  int curr = 0;
  for (int i = 0; i < b; i++) {
    len += dp2[curr];
    curr = dp2[curr] + curr;
    curr %= clen;
  }
  int ans = len / (clen * d);
  cout << ans;
  return 0;
}
