#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3f;
int fx[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
template <typename T>
inline T gcd(T a, T b) {
  return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
inline T lcm(T a, T b) {
  if (a * b > INFF) return 0;
  return a / gcd(a, b) * b;
}
template <typename T>
inline T lowbit(T x) {
  return x & (-x);
}
template <typename T>
inline bool mishu(T x) {
  return x > 0 ? (x & (x - 1)) == 0 : false;
}
inline char nc() {
  static char buf[1000000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
template <typename T>
inline int read(T& sum) {
  char ch = getchar();
  if (ch == EOF || ch == -1) return 0;
  int tf = 0;
  sum = 0;
  while ((ch < '0' || ch > '9') && (ch != '-')) ch = getchar();
  tf = ((ch == '-') && (ch = getchar()));
  while (ch >= '0' && ch <= '9') sum = sum * 10 + (ch - 48), ch = getchar();
  (tf) && (sum = -sum);
  return 1;
}
template <typename T>
inline void print(T k) {
  int num = 0, ch[20];
  if (k == 0) {
    putchar('0');
    return;
  }
  (k < 0) && (putchar('-'), k = -k);
  while (k > 0) ch[++num] = k % 10, k /= 10;
  while (num) putchar(ch[num--] + 48);
}
template <typename T1, typename T2, typename T3>
long long qmul(T1 a, T2 b, T3 p) {
  long long w = 0;
  while (b) {
    if (b & 1) w = (w + a) % p;
    b >>= 1;
    a = (a + a) % p;
  }
  return w;
}
template <typename T1, typename T2, typename T3>
long long qpow(T1 a, T2 b, T3 p) {
  long long w = 1;
  while (b) {
    if (b & 1) w = (qmul(w, a, p)) % p;
    b >>= 1;
    a = (qmul(a, a, p)) % p;
  }
  return w;
}
template <typename T>
long long exgcd(T a, T b, T& x, T& y) {
  if (b == 0) {
    x = 1, y = 0;
    return (long long)a;
  }
  long long r = exgcd(b, a % b, y, x);
  y -= a / b * x;
  return r;
}
int b, d, cnt[105] = {0}, nxt[105];
string a, c;
int main() {
  ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);
  cin >> b >> d >> a >> c;
  int lenc = c.size(), lena = a.size();
  for (int i = (0); i < (lenc); ++i) {
    int temp = i;
    for (int j = (0); j < (lena); ++j) {
      if (a[j] == c[temp]) {
        temp++;
        if (temp == lenc) cnt[i]++, temp = 0;
      }
    }
    nxt[i] = temp;
  }
  int j = 0;
  long long sum = 0;
  for (int i = (1); i <= (b); ++i) {
    sum += cnt[j];
    j = nxt[j];
  }
  cout << sum / d << endl;
  return 0;
}
