#include <bits/stdc++.h>
using namespace std;
char a[110];
char b[110];
int c, d;
int dp[110][2];
bool vis[110];
int main() {
  while (~scanf("%d %d", &c, &d)) {
    scanf("%s %s", a, b);
    memset(vis, 0, sizeof(vis));
    int p = 0;
    int lenb = strlen(b);
    memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;
    for (int i = 1;; i++) {
      dp[i][0] = dp[i - 1][0];
      for (int j = 0; a[j]; j++)
        if (b[p] == a[j]) {
          p = (p + 1) % lenb;
          if (p == 0) dp[i][0]++;
        }
      dp[i][1] = p;
      if (vis[p]) {
        break;
      } else
        vis[p] = 1;
    }
    long long total = 0;
    if (c < 110 && dp[c][0] != -1)
      total = dp[c][0];
    else {
      int fi = 0;
      for (int i = 1;; i++)
        if (dp[i][1] == p) {
          fi = i;
          break;
        }
      total += dp[fi][0];
      c -= fi;
      int second = 0;
      for (int i = fi + 1;; i++)
        if (dp[i][1] == p) {
          second = i;
          break;
        }
      int T = second - fi;
      int get = dp[second][0] - dp[fi][0];
      total += c / T * get;
      c %= T;
      total += dp[fi + c][0] - dp[fi][0];
    }
    printf("%I64d\n", total / d);
  }
}
