#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const double tau = 2 * pi;
const double epsilon = 1e-9;
const int MAX_TEMPLATE = 110;
string a;
int b;
string c;
int d;
int nObtained[MAX_TEMPLATE];
bool repeat[MAX_TEMPLATE];
int lastRepeat[MAX_TEMPLATE];
int main(int argc, const char* argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> b >> d >> a >> c;
  int nA = 0, curC = 0;
  while (!repeat[curC]) {
    repeat[curC] = true;
    lastRepeat[curC] = nA;
    nObtained[nA + 1] = nObtained[nA];
    bool foundnew = false;
    for (int i = 0; i < ((int)a.size()); i++)
      if (a[i] == c[curC]) {
        ++curC;
        if (curC == ((int)c.size())) {
          ++nObtained[nA + 1];
          curC = 0;
        }
        foundnew = true;
      }
    if (!foundnew) {
      cout << "0\n";
      return 0;
    }
    ++nA;
  }
  if (b <= nA)
    cout << nObtained[b] / d;
  else {
    int nCinAB = nObtained[lastRepeat[curC]] +
                 (b - lastRepeat[curC]) / (nA - lastRepeat[curC]) *
                     (nObtained[nA] - nObtained[lastRepeat[curC]]) +
                 nObtained[(b - lastRepeat[curC]) % (nA - lastRepeat[curC]) +
                           lastRepeat[curC]] -
                 nObtained[lastRepeat[curC]];
    cout << nCinAB / d << '\n';
  }
  return 0;
}
