#include <bits/stdc++.h>
using namespace std;
const int MAXN = 120;
const int inf = 0x3f3f3f3f;
int b, d;
char a[MAXN], c[MAXN];
int tot[MAXN], e[MAXN];
int n;
int main() {
  scanf("%d%d", &b, &d);
  scanf("%s", a);
  scanf("%s", c);
  int l1 = strlen(a), l2 = strlen(c);
  for (int i = 0; i < l2; ++i) {
    int cur = i, maxlen = 0, ed;
    for (int j = 0; j < l1; ++j)
      if (c[cur] == a[j]) {
        cur++;
        cur %= l2;
        maxlen++;
        ed = cur;
      }
    tot[i] = maxlen;
    e[i] = ed;
  }
  long long len = 0;
  long long len2 = l2 * d;
  int cur = 0;
  for (int i = 0; i < b; ++i) {
    len += tot[cur];
    cur = e[cur];
  }
  cout << len / len2 << endl;
  return 0;
}
