#include <bits/stdc++.h>
using namespace std;
int nextt[201];
int cnt[201];
bool used[201];
int main() {
  int b, d, j, i;
  cin >> b >> d;
  string a, c;
  cin >> a >> c;
  for (i = 0; i < c.size(); i++) {
    int id = i;
    for (j = 0; j < a.size(); j++) {
      if (c[id] == a[j]) {
        id++;
        if (id == c.size()) id = 0;
        if (id == i) cnt[i]++;
      }
    }
    nextt[i] = id;
  }
  int id = 0;
  int ans = 0;
  for (i = 1; i <= b; i++) {
    ans += cnt[id];
    int nex = nextt[id];
    if (nex < id) ans++;
    id = nex;
  }
  cout << ans / d;
}
