#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const auto INF = 0x3f3f3f3f;
const int N = 1e2 + 5;
char a[N], b[N];
int dp[N], nextt[N];
int main() {
  int A, B;
  scanf("%d%d", &A, &B);
  scanf("%s%s", a, b);
  int lena = (int)strlen(a);
  int lenb = (int)strlen(b);
  for (int i = 0; i < lenb; i++) {
    int pos = i;
    for (int j = 0; j < lena; j++) {
      if (a[j] == b[pos]) pos++;
      if (pos == lenb) {
        pos = 0;
        dp[i]++;
      }
    }
    nextt[i] = pos;
  }
  int answer = 0, pos = 0;
  while (A--) {
    answer += dp[pos];
    pos = nextt[pos];
  }
  printf("%d\n", answer / B);
}
