#include <bits/stdc++.h>
using namespace std;
char a[110], c[110];
int n, m, b, d, f[110], ans;
int main() {
  cin >> b >> d >> a >> c;
  n = strlen(a);
  m = strlen(c);
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++)
      if (a[j] == c[(i + f[i]) % m]) f[i]++;
  for (int i = 0; i < b; i++) ans += f[ans % m];
  ans /= m;
  ans /= d;
  cout << ans;
}
