#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
int B, D;
int N, M;
char A[MAXN], C[MAXN];
int match[MAXN];
bool vis[MAXN];
vector<int> cyc;
int main() {
  if (fopen("input.txt", "r")) {
    freopen("input.txt", "r", stdin);
  }
  scanf("%d %d %s %s", &B, &D, A, C);
  N = strlen(A);
  M = strlen(C);
  for (int i = 0; i < N; i++) {
    int cur = 0, ind = i - 1;
    int nstep = 0;
    for (; cur < M; cur++) {
      bool found = false;
      for (int j = 0; j < N; j++) {
        ind = (ind + 1) % N;
        nstep++;
        if (A[ind] == C[cur]) {
          found = true;
          break;
        }
      }
      if (!found) {
        assert(i == 0);
        puts("0");
        return 0;
      }
    }
    match[i] = nstep;
  }
  cyc.push_back(0);
  vis[0] = true;
  int scyc, cur = 0;
  while (true) {
    int nxt = (cur + match[cur]) % N;
    if (vis[nxt]) {
      scyc = find((cyc).begin(), (cyc).end(), nxt) - cyc.begin();
      break;
    }
    vis[nxt] = true;
    cyc.push_back(nxt);
    cur = nxt;
  }
  int nmatch = 0, rem = N * B;
  for (int i = 0; i < scyc; i++) {
    int nrem = rem - match[cyc[i]];
    if (nrem < 0) {
      printf("%d\n", nmatch / D);
      return 0;
    }
    nmatch++;
    rem = nrem;
  }
  int mcyc = 0;
  for (int i = scyc; i < cyc.size(); i++) {
    mcyc += match[cyc[i]];
  }
  assert(mcyc);
  nmatch += (rem / mcyc) * (cyc.size() - scyc);
  rem %= mcyc;
  for (int i = scyc; i < cyc.size(); i++) {
    int nrem = rem - match[cyc[i]];
    if (nrem < 0) {
      break;
    }
    nmatch++;
    rem = nrem;
  }
  printf("%d\n", nmatch / D);
}
