#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long b, d;
  cin >> b >> d;
  string a, c;
  cin >> a >> c;
  long long x[110] = {0}, y[110] = {0};
  for (long long i = 0; i < c.size(); i++) {
    long long p = i;
    for (long long j = 0; j < a.size(); j++) {
      if (c[p] == a[j]) {
        p++;
        if (p == c.size()) x[i]++, p = 0;
      }
    }
    y[i] = p;
  }
  long long ans = 0, p = 0;
  for (long long i = 0; i < b; i++) {
    ans += x[p];
    p = y[p];
  }
  cout << ans / d;
  return 0;
}
