#include <bits/stdc++.h>
using namespace std;
const int L = 100 + 10;
int b, d, al, cl;
char a[L], c[L];
int ass1[L][2];
void solve1() {
  for (int i = 0; c[i]; ++i) {
    int j = i;
    ass1[i][0] = 0;
    for (int k = 0; a[k]; ++k) {
      if (a[k] == c[j]) {
        ++j;
      }
      if (j == cl) {
        ++ass1[i][0];
        j = 0;
      }
    }
    ass1[i][1] = j;
  }
}
int solve2() {
  int s = 0, r = 0;
  for (int i = 0; i < b; ++i) {
    r += ass1[s][0];
    s = ass1[s][1];
  }
  return r;
}
int main() {
  cin >> b >> d;
  cin >> a >> c;
  al = strlen(a);
  cl = strlen(c);
  solve1();
  cout << solve2() / d << endl;
  return 0;
}
