#include <bits/stdc++.h>
using namespace std;
const int MAXN = 111111;
const int oo = (int)(1e9);
const long double PI = 3.141592653589793;
template <class T>
inline bool chkmin(T &a, T b) {
  return a > b ? a = b, true : false;
}
template <class T>
inline bool chkmax(T &a, T b) {
  return a < b ? a = b, true : false;
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <typename T>
T gcd(T x, T y) {
  for (T t; x; t = x, x = y % x, y = t)
    ;
  return y;
}
template <typename TT>
void read(TT &x) {
  char ch;
  for (ch = getchar(); ch > '9' || ch < '0'; ch = getchar())
    ;
  for (x = 0; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - 48;
}
int n, m, f[25][111], g[25][111];
char a[111], b[111];
void get(int be, int &s, int &j) {
  s = 0, j = be;
  for (int i = 1; i <= n; i++)
    if (a[i] == b[j]) {
      j++;
      if (j > m) s++, j = 1;
    }
}
void Init() {
  int c, d;
  scanf("%d%d", &c, &d);
  ;
  scanf("%s", a + 1);
  ;
  scanf("%s", b + 1);
  ;
  n = strlen(a + 1);
  m = strlen(b + 1);
  memset(f, 0, sizeof(f));
  ;
  memset(g, 0, sizeof(g));
  ;
  for (int i = 1; i <= m; i++) get(i, f[0][i], g[0][i]);
  for (int i = 0; i < 24; i++)
    for (int j = 1; j <= m; j++) {
      f[i + 1][j] = f[i][j] + f[i][g[i][j]];
      g[i + 1][j] = g[i][g[i][j]];
    }
  int F = 0, G = 1;
  for (int i = 0; i < 24; i++) {
    if (c & 1) {
      F += f[i][G];
      G = g[i][G];
    }
    c /= 2;
  }
  cout << F / d;
}
int main() {
  Init();
  return 0;
}
