#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e16;
const long long maxn = 128;
const long long maxlog = 60;
long long a, b;
string s, t;
long long dp[maxlog][maxn];
long long ans;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> a >> b;
  cin >> s >> t;
  string S = "";
  for (long long i = 100; i--; S += s)
    ;
  for (long long i = 0; i < s.size(); i++) {
    long long p1 = 0, p2 = i;
    for (; p1 < t.size(); p1++, p2++) {
      for (; p2 < S.size() and S[p2] != t[p1]; p2++)
        ;
      if (p2 == S.size()) break;
    }
    if (p1 == t.size())
      dp[0][i] = p2 - i;
    else
      dp[0][i] = inf;
  }
  for (long long j = 1; j < maxlog; j++)
    for (long long i = 0; i < s.size(); i++)
      dp[j][i] =
          min(dp[j - 1][i] + dp[j - 1][(i + dp[j - 1][i]) % s.size()], inf);
  long long len = 0;
  for (long long j = maxlog; j--;)
    if (dp[j][len % s.size()] + len <= a * s.size())
      ans |= 1ll << j, len = len + dp[j][len % s.size()];
  cout << ans / b << endl;
  return 0;
}
