#include <bits/stdc++.h>
using namespace std;
long a, b, n, i, j, f[200];
long long ans = 0;
string s1, s2;
int main() {
  cin >> a >> b >> s1 >> s2;
  n = s2.length();
  for (i = 0; i < n; i++)
    for (j = 0; j < s1.length(); j++)
      if (s1[j] == s2[(i + f[i]) % n]) f[i]++;
  for (i = 0; i < a; i++) ans += f[ans % n];
  cout << ans / (n * b) << endl;
  return 0;
}
