#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
int b, d, dp[110][2];
string a, c;
int main() {
  while (cin >> b >> d) {
    cin >> a >> c;
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < c.size(); ++i) {
      dp[i][1] = 0;
      int p = i;
      for (int j = 0; j < a.size(); ++j) {
        if (a[j] == c[p]) {
          p++;
          if (p == c.size()) {
            dp[i][1]++;
            p = 0;
          }
        }
      }
      dp[i][0] = p;
    }
    int ans = 0, p = 0;
    for (int i = 0; i < b; ++i) {
      ans += dp[p][1];
      p = dp[p][0];
    }
    cout << ans / d << endl;
  }
  return 0;
}
