#include <bits/stdc++.h>
using namespace std;
const int N = 120;
const int M = 1;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
int b, d, l, l1, nxt[N], num[N], c[N], mat[N];
char s[N], s1[N];
bool v[26], v1[26], f[N];
bool judge() {
  for (int i = 0; i < l; ++i) v[s[i] - 'a'] = 1;
  for (int i = 0; i < l1; ++i) v1[s1[i] - 'a'] = 1;
  for (int i = 0; i < 26; ++i)
    if (v1[i] && !v[i]) return 0;
  return 1;
}
int main() {
  scanf("%d%d", &b, &d);
  scanf("%s%s", s, s1);
  l = strlen(s);
  l1 = strlen(s1);
  if (!judge()) {
    printf("0\n");
  } else {
    for (int i = 0; i < l; ++i) {
      int k = i;
      for (int j = 0; j < l1; ++j) {
        while (s1[j] != s[k % l]) ++k;
        ++k;
      }
      num[i] = k / l;
      nxt[i] = k % l;
    }
    memset(f, 0, sizeof(f));
    f[0] = 1, c[0] = 0, mat[0] = 0;
    int delta = 0;
    int cnt, m = 0, cp;
    int i = 0;
    while (1) {
      ++m;
      delta += num[i];
      i = nxt[i];
      if (f[i]) {
        cnt = delta - c[i], cp = m - mat[i];
        break;
      }
      f[i] = 1, c[i] = delta, mat[i] = m;
    }
    int sum = 0;
    if (b <= c[i]) {
      int j = 0;
      while (1) {
        b -= num[j], j = nxt[j];
        if (b < 0) break;
        if (b == 0 && j) break;
        ++sum;
      }
    } else {
      sum = mat[i];
      b -= c[i];
      sum += (b - 1) / cnt * cp;
      b -= (b - 1) / cnt * cnt;
      while (1) {
        b -= num[i];
        i = nxt[i];
        if (b < 0) break;
        if (b == 0 && i) break;
        ++sum;
      }
    }
    printf("%d\n", sum / d);
  }
  return 0;
}
