#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e2 + 2;
int A, B;
int nx[MAXN];
int add[MAXN];
char a[MAXN];
char b[MAXN];
int main() {
  scanf(" %d %d", &A, &B);
  scanf(" %s %s", a, b);
  int la = strlen(a);
  int lb = strlen(b);
  for (int i = 0; i < lb; i++) {
    int cur = i;
    int cnt = 0;
    for (int j = 0; j < la; j++)
      if (a[j] == b[cur]) {
        cur++;
        if (cur == lb) {
          cur = 0;
          cnt++;
        }
      }
    nx[i] = cur;
    add[i] = cnt;
  }
  int res = 0;
  int cur = 0;
  for (int i = 0; i < A; i++) {
    res += add[cur];
    cur = nx[cur];
  }
  printf("%d\n", res / B);
  return 0;
}
