#include <bits/stdc++.h>
using namespace std;
char stra[110];
char strb[110];
int mark[110];
int g[11000];
int main() {
  int b, d;
  scanf("%d%d", &b, &d);
  scanf("%s", stra);
  scanf("%s", strb);
  int lena = strlen(stra);
  int lenb = strlen(strb);
  memset(mark, -1, sizeof(mark));
  mark[0] = 0;
  int pos = 0;
  int key = 0;
  int cnt = 0;
  int num = 0;
  for (int ii = 1; ii <= 1000; ii++) {
    int sum = 0;
    for (int i = 0; i < lena; i++) {
      if (stra[i] == strb[pos]) {
        pos++;
        if (pos == lenb) {
          sum++;
          pos = 0;
        }
      }
    }
    g[ii] = sum;
    if (mark[pos] == -1)
      mark[pos] = ii;
    else {
      key = mark[pos];
      cnt = ii - key;
      for (int ti = key + 1; ti <= ii; ti++) num += g[ti];
      break;
    }
  }
  int ans = 0;
  if (b <= key) {
    for (int i = 1; i <= b; i++) ans += g[i];
  } else {
    int tb = (b - key) / cnt;
    int tt = (b - key) - tb * cnt;
    for (int i = 1; i <= key; i++) ans += g[i];
    ans += tb * num;
    for (int i = key + 1; i <= key + tt; i++) ans += g[i];
  }
  printf("%d\n", ans / d);
  return 0;
}
