#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e2 + 5;
const long long INF = 2e5;
long long b, d, n1, n2, vis[105], viscnt[105], precnt, midcnt, lastcnt, T, cnt,
    preT;
char str1[105], str2[105];
bool getmatch() {
  for (long long i = 1; i <= n2; i++) {
    long long flag = 0;
    for (long long j = 1; j <= n1; j++) {
      if (str2[i] == str1[j]) {
        flag = 1;
        break;
      }
    }
    if (!flag) {
      return false;
    }
  }
  return true;
}
void getleft(long long st, long long lef) {
  if (st == n1 + 1) {
    lef++;
    st = 1;
  }
  long long now = 1, nowcnt = 0;
  for (long long i = lef; i <= b; i++) {
    for (long long j = (i == lef ? st : 1); j <= n1; j++) {
      if (str1[j] == str2[now]) {
        now++;
        if (now == n2 + 1) {
          now = 1;
          nowcnt++;
        }
      }
    }
  }
  lastcnt = nowcnt;
}
void getperiod() {
  long long now = 1, nowcnt = 0;
  for (long long i = 1; i <= b; i++) {
    for (long long j = 1; j <= n1; j++) {
      if (str1[j] == str2[now]) {
        now++;
        if (now == n2 + 1) {
          now = 1;
          nowcnt++;
          if (vis[j]) {
            T = i - vis[j];
            cnt = nowcnt - viscnt[j];
            preT = vis[j];
            precnt = viscnt[j];
            long long lef = (b - preT) / T * T + preT;
            midcnt = (b - preT) / T * cnt;
            getleft(j + 1, lef);
            return;
          } else {
            vis[j] = i;
            viscnt[j] = nowcnt;
          }
        }
      }
    }
  }
}
int main() {
  scanf("%lld %lld", &b, &d);
  scanf("%s", str1 + 1);
  scanf("%s", str2 + 1);
  n1 = strlen(str1 + 1);
  n2 = strlen(str2 + 1);
  if (getmatch()) {
    getperiod();
    if (!T) {
      getleft(1, 1);
    }
    printf("%lld", (precnt + midcnt + lastcnt) / d);
  } else {
    printf("0\n");
  }
}
