#include <bits/stdc++.h>
using namespace std;
const int size = 210000, mod = 1000000007, inf = 0x3f3f3f3f;
const long long llinf = 0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1.0), eps = 1e-6;
int month[2][13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
                    0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int nex[2][8] = {-1, 0, 1, 0, -1, 1, 1, -1, 0, 1, 0, -1, 1, 1, 0, 0};
template <class T>
void inc(T& a, T b) {
  a = (a + b) % mod;
}
template <class T>
T modu(T a) {
  return (a % mod + mod) % mod;
}
template <class T>
void crl(T* l, T* r, int step) {
  T tmp = *l;
  for (T* i = l; i < r; i += step) *i = *(i + step);
  *(r - 1) = tmp;
}
template <class T>
void crr(T* l, T* r, int step) {
  T tmp = *(r - 1);
  for (T* i = r - 1; i > l; i -= step) *i = *(i - step);
  *l = tmp;
}
bool dbeq(double a, double b) { return fabs(a - b) < eps; }
template <class T>
void cmin(T& a, T b) {
  a = min(a, b);
}
template <class T>
void cmax(T& a, T b) {
  a = max(a, b);
}
string a, c;
int b, d, f[110], num[110], ans;
int main() {
  cin >> b >> d >> a >> c;
  for (int i = 0; i < c.size(); i++)
    for (int j = 0; j < a.size(); j++)
      if (c[(i + f[i]) % c.size()] == a[j]) f[i]++;
  for (int i = 0; i < b; i++) ans += f[ans % c.size()];
  printf("%d\n", ans / c.size() / d);
  return 0;
}
