#include <bits/stdc++.h>
using namespace std;
char s[1100], t[1100];
int b, d;
pair<int, int> Record[1100];
int main() {
  scanf("%d%d", &b, &d);
  scanf("%s%s", s, t);
  int len1 = strlen(s), len2 = strlen(t);
  int i, j;
  for (i = 0; i < len2; i++) {
    pair<int, int> now(0, i);
    for (j = 0; j < len1; j++) {
      if (s[j] == t[now.second]) {
        now.second++;
        if (now.second == len2) {
          now.second = 0;
          now.first++;
        }
      }
    }
    Record[i] = now;
  }
  int ret = 0;
  int cur = 0;
  for (i = 0; i < b; i++) {
    ret += Record[cur].first;
    cur = Record[cur].second;
  }
  printf("%d\n", ret / d);
  return 0;
}
