#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 7;
int n, m, b, d, dp[N];
char a[N], c[N];
int main() {
  scanf("%d%d %s %s", &b, &d, a, c);
  n = strlen(a), m = strlen(c);
  for (int i = (0); i < (m); ++i) {
    dp[i] = 0;
    for (int j = (0); j < (n); ++j)
      if (a[j] == c[(i + dp[i]) % m]) ++dp[i];
  }
  int L = 0;
  for (int i = (0); i < (b); ++i) L += dp[L % m];
  printf("%d", L / m / d);
  return 0;
}
