#include <bits/stdc++.h>
using namespace std;
string a, c;
int dp[105];
int b, d, t;
int main() {
  cin >> b >> d;
  cin >> a >> c;
  for (int i = 0; i < c.length(); i++) {
    for (int j = 0; j < a.length(); j++) {
      if (a[j] == c[(i + dp[i]) % c.length()]) {
        dp[i]++;
      }
    }
  }
  for (int i = 0; i < b; i++) {
    t += dp[t % c.length()];
  }
  cout << t / c.length() / d << '\n';
  return 0;
}
