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