#include <bits/stdc++.h>
using namespace std;
pair<int, long long> nxt[31][105];
char a[105], c[105];
int main() {
  long long b, d;
  scanf("%lld%lld%s%s", &b, &d, a, c);
  int al = strlen(a), cl = strlen(c);
  for (int i = 0; i < cl; i++) {
    int cur = i;
    for (int j = 0; j < al; j++) {
      if (c[cur] == a[j]) cur++;
      if (cur == cl) {
        nxt[0][i].second++;
        cur = 0;
      }
    }
    nxt[0][i].first = cur;
  }
  for (int k = 1; k < 31; k++) {
    for (int i = 0; i < cl; i++) {
      nxt[k][i].first = nxt[k - 1][nxt[k - 1][i].first].first;
      nxt[k][i].second =
          nxt[k - 1][nxt[k - 1][i].first].second + nxt[k - 1][i].second;
    }
  }
  long long ans = 0;
  int cur = 0;
  for (int i = 0; i < 31; i++) {
    if (b & (1 << i)) {
      ans += nxt[i][cur].second;
      cur = nxt[i][cur].first;
    }
  }
  printf("%lld\n", ans / d);
  return 0;
}
