#include <bits/stdc++.h>
using namespace std;
int a, b, lengthc, lengthd, record[110], dp[110];
char c[110], d[110];
void findcircle() {
  for (int i = 0; i < lengthd; i++) {
    int p = i;
    for (int j = 0; j < lengthc; j++) {
      if (d[p] == c[j]) p++;
      if (p == lengthd) {
        record[i]++;
        p = 0;
      }
    }
    dp[i] = p;
  }
}
void solve() {
  scanf("%d%d\n%s\n%s\n", &a, &b, c, d);
  lengthc = strlen(c);
  lengthd = strlen(d);
  findcircle();
  int total = 0, p = 0;
  for (int i = 0; i < a; i++) {
    total += record[p];
    p = dp[p];
  }
  total /= b;
  printf("%d\n", total);
}
int main() {
  solve();
  return 0;
}
