#include <bits/stdc++.h>
using namespace std;
int dp[128];
int main() {
  int b, d;
  string a, c;
  cin >> b >> d >> a >> c;
  const int alen = a.size();
  const int clen = c.size();
  for (int i = 0; i < (int)(clen); i++) {
    dp[i] = 0;
    for (int j = 0; j < (int)(alen); j++) {
      if (c[(i + dp[i]) % clen] == a[j]) {
        dp[i]++;
      }
    }
  }
  long long p = 0;
  for (int i = 0; i < (int)(b); i++) {
    p += dp[p % clen];
  }
  cout << p / (clen * d) << endl;
  return 0;
}
