#include <bits/stdc++.h>
using namespace std;
string s1, s2;
int a, b;
int nxt[205], cnt[205];
int main() {
  scanf("%d%d", &a, &b);
  cin >> s1 >> s2;
  for (int i = 0; i < s2.size(); i++) {
    int pos = i;
    for (int r = 0; r < s1.size(); r++) {
      if (s2[pos] == s1[r]) {
        pos++;
        if (pos == s2.size()) cnt[i]++, pos = 0;
      }
    }
    nxt[i] = pos;
  }
  int ans = 0;
  int poss = 0;
  for (int i = 1; i <= a; i++) ans += cnt[poss], poss = nxt[poss];
  cout << ans / b;
}
