#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 5;
int n, m, b, d;
char a[N], c[N];
int cnt[N], to[N];
int dfs(int p, int rem) {
  int ret = 0;
  while (rem--) {
    ret += cnt[p];
    p = to[p];
  }
  return ret;
}
int main() {
  scanf("%d%d%s%s", &b, &d, a, c);
  n = strlen(a);
  m = strlen(c);
  for (int k = 0; k < m; ++k) {
    int j = k, cc = 0;
    for (int i = 0; i < n; ++i) {
      if (a[i] == c[j]) ++j;
      if (j == m) ++cc, j = 0;
    }
    cnt[k] = cc;
    to[k] = j;
  }
  printf("%d", dfs(0, b) / d);
  return 0;
}
