#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  int b, d, nPs, nBBs, nCycles, nLeftBBs;
  string a, c;
  cin >> b >> d >> a >> c;
  int i = 0, j = 0, p = 0, bb = 0;
  int P[109], BB[109];
  memset(P, -1, sizeof(P));
  memset(BB, -1, sizeof(BB));
  while (true) {
    if (a[i] != c[j]) goto END_OF_LOOP;
    ++j;
    if (j != c.size()) goto END_OF_LOOP;
    ++p, j = 0;
    if (P[i] == -1) {
      P[i] = p, BB[i] = bb;
      goto END_OF_LOOP;
    }
    nPs = p - P[i], nBBs = bb - BB[i], nLeftBBs = b - bb - 1;
    nCycles = nLeftBBs / nBBs;
    p += nCycles * nPs;
    bb += nCycles * bb;
    ++i;
    if (i == a.size()) i = 0, ++bb;
    goto SECOND_LOOP;
  END_OF_LOOP:
    ++i;
    if (i == a.size()) {
      ++bb, i = 0;
      if (bb == b || (bb == 100 && p == 0)) goto END;
    }
  }
SECOND_LOOP:
  while (bb < b) {
    if (a[i] == c[j]) ++j;
    if (j == c.size()) ++p, j = 0;
    ++i;
    if (i == a.size()) i = 0, ++bb;
  }
END:
  cout << p / d;
  return 0;
}
