#include <bits/stdc++.h>
using namespace std;
const long long maxN = 2e5 + 12;
long long n, m, b, d, ans, j2, dp[maxN], how[maxN];
string s, t;
int32_t main() {
  cin >> b >> d >> s >> t;
  n = s.size();
  m = t.size();
  for (long long i = 0; i < m; i++) {
    j2 = i;
    ans = 0;
    for (long long j = 0; j < n; j++) {
      if (s[j] == t[j2]) {
        j2++;
        if (j2 == m) ans++, j2 = 0;
      }
    }
    dp[i] = ans, how[i] = j2;
  }
  j2 = 0;
  ans = 0;
  for (long long i = 1; i <= b; i++) {
    ans += dp[j2];
    j2 = how[j2];
  }
  cout << ans / d << endl;
}
