#include <bits/stdc++.h>
using namespace std;
const int NMAX = 105;
string s1, s2;
int len[NMAX];
int main() {
  int a, b, i, j, N, M;
  cin >> a >> b >> s1 >> s2;
  for (i = 0; i < s2.size(); ++i)
    for (j = 0; j < s1.size(); ++j)
      if (s2[(i + len[i]) % (s2.size())] == s1[j]) ++len[i];
  long long rez = 0;
  for (i = 0; i < a; ++i) rez += 1LL * len[rez % (s2.size())];
  cout << rez / (1LL * b * (s2.size()));
  return 0;
}
