#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 + 10;
int b, d;
char a[MAXN];
char c[MAXN];
int la, lc;
long long ans = 0;
int cnt[MAXN];
int nt[MAXN];
int main() {
  scanf("%d%d", &b, &d);
  scanf("%s", a);
  scanf("%s", c);
  la = strlen(a);
  lc = strlen(c);
  for (int i = 0; i < lc; i++) {
    int x = i;
    for (int j = 0; j < la; j++) {
      if (a[j] == c[x]) {
        x++;
        if (x == lc) {
          cnt[i] += 1;
          x = 0;
        }
      }
    }
    nt[i] = x;
  }
  int x = 0;
  for (int i = 1; i <= b; i++) {
    ans += (long long)cnt[x];
    x = nt[x];
  }
  cout << ans / d;
  return 0;
}
