#include <bits/stdc++.h>
using namespace std;
const int M = 10000 + 10;
int nxt[M];
int cnt[M];
int main() {
  int b, d;
  cin >> b >> d;
  string a, c;
  cin >> a >> c;
  int alen = a.length();
  int clen = c.length();
  set<int> sa;
  for (int i = 0; i < a.length(); i++) {
    sa.insert(a[i]);
  }
  bool ok = true;
  for (int i = 0; i < c.length(); i++) {
    if (sa.find(c[i]) == sa.end()) {
      ok = false;
    }
  }
  if (!ok) {
    cout << 0 << endl;
  } else {
    for (int i = 0; i < clen; i++) {
      int pos = i;
      for (int j = 0; j < alen; j++) {
        if (c[pos] == a[j]) {
          pos++;
          if (pos == clen) {
            pos = 0;
            cnt[i]++;
          }
        } else {
          ;
        }
      }
      nxt[i] = pos;
    }
    long long int ans = 0;
    int pos = 0;
    for (int i = 0; i < b; i++) {
      ans = ans + cnt[pos];
      pos = nxt[pos];
    }
    ans = ans / d;
    cout << ans << endl;
  }
  return 0;
}
