#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int inf = 50000000;
const int maxn = 111;
char a[maxn], c[maxn];
int dp[maxn][maxn], nxt[maxn][30], pos[30], n, m;
int solve(int cn, int cm) {
  if (cm > m) return 0;
  if (cn > n) return solve(1, cm);
  if (dp[cn][cm] != -1) return dp[cn][cm];
  int ret;
  if (nxt[cn][c[cm] - 'a'])
    ret =
        nxt[cn][c[cm] - 'a'] - cn + 1 + solve(nxt[cn][c[cm] - 'a'] + 1, cm + 1);
  else {
    if (cn == 1)
      ret = mod;
    else
      ret = n - cn + 1 + solve(1, cm);
  }
  return dp[cn][cm] = ret;
}
int main() {
  int b, d, i, j, cn, cm, tc, ind, temp, hold, cnt, x, y;
  memset(dp, -1, sizeof(dp));
  scanf("%d%d%s%s", &b, &d, a + 1, c + 1);
  n = strlen(a + 1);
  m = strlen(c + 1);
  for (i = n; i >= 1; i--) {
    pos[a[i] - 'a'] = i;
    for (j = 0; j < 26; j++) nxt[i][j] = pos[j];
  }
  cn = cm = 1;
  tc = 0;
  while (1) {
    ind = cn % n;
    if (!ind) ind = n;
    x = nxt[ind][c[1] - 'a'];
    if (!x && tc) {
      y = (cn - 1) / n;
      y++;
      cn = y * n + 1;
      break;
    }
    temp = solve(ind, 1);
    cn += temp;
    if (cn <= ((b * n) + 1))
      tc++;
    else
      break;
    if ((cn % n) == 1) break;
  }
  hold = cn - 1;
  cnt = 0;
  while ((cn + hold) <= ((b * n) + 1)) {
    cn += hold;
    cnt++;
  }
  tc *= (cnt + 1);
  while (1) {
    ind = cn % n;
    if (!ind) ind = n;
    temp = solve(ind, 1);
    if ((cn + temp) > ((b * n) + 1)) break;
    cn += temp;
    tc++;
  }
  int ans = tc / d;
  printf("%d\n", ans);
  return 0;
}
