#include <bits/stdc++.h>
using namespace std;
const int INF = 1E9 + 7;
template <class C>
void mini(C& a4, C b4) {
  a4 = min(a4, b4);
}
template <class C>
void maxi(C& a4, C b4) {
  a4 = max(a4, b4);
}
int b, d, cnt[107];
string a, c;
int main() {
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  cin >> b >> d >> a >> c;
  int n = ((int)(a).size());
  int m = ((int)(c).size());
  for (int i = 0; i < (m); ++i) {
    int poz = 0;
    for (int j = 0; j < (n); ++j)
      if (a[j] == c[(i + poz) % m]) poz++;
    cnt[i] = poz;
  }
  int poz = 0;
  for (int i = 0; i < (b); ++i) poz += cnt[poz % m];
  cout << (poz / (m * d)) << endl;
  return 0;
}
