#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000")
using namespace std;
int ans, i, j, k, b, d, p[105], q[105], n, m;
char a[105], c[105];
int main() {
  cin >> b >> d;
  cin >> a;
  cin >> c;
  n = strlen(a);
  m = strlen(c);
  for (i = 0; i < m; i++) {
    j = 0;
    k = i;
    p[i] = 0;
    while (j < n) {
      while (j < n && a[j] != c[k]) j++;
      if (j < n && a[j] == c[k]) {
        p[i]++;
        k++;
        if (k == m) k -= m;
        j++;
      }
    }
    q[i] = p[i] % m;
  }
  ans = 0;
  j = 0;
  for (i = 1; i <= b; i++) {
    ans += p[j];
    j += q[j];
    while (j >= m) j -= m;
  }
  cout << ans / m / d << endl;
}
