#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 2, MOD = 1e9 + 7;
using vi = vector<long long>;
using vp = vector<pair<long long, long long>>;
mt19937 Flash_new_51(515151);
long long a[N];
string s, s1;
long long kek(long long l, long long r) {
  long long p = 0, sum = 0;
  for (long long i = l; i <= r; i++) {
    long long k = i % s.size();
    if (s[k] == s1[p]) {
      if (p == s1.size() - 1) sum++;
      p = (p + 1) % s1.size();
    }
  }
  return sum;
}
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  long long b, d;
  cin >> b >> d >> s >> s1;
  for (long long i = 0; i < s1.size(); i++) {
    bool ok = false;
    for (long long j = 0; j < s.size(); j++) {
      ok = ok | (s1[i] == s[j]);
    }
    if (!ok) {
      cout << 0;
      return 0;
    }
  }
  long long l = 0, r = 0;
  long long lens = s.size(), lens1 = s1.size(), p = 0;
  fill(a, a + (long long)1e4 + 1, -1);
  for (long long i = 0; i < 1e4; i++) {
    long long k = i % lens;
    if (s[k] == s1[p]) {
      if (p == 0) {
        if (a[k] == -1)
          a[k] = i;
        else {
          l = a[k];
          r = i - 1;
        }
      }
      p = (p + 1) % lens1;
    }
  }
  long long ans = kek(0, min(l, b * lens) - 1);
  long long mem = 0;
  mem = (b * lens - l) / (r - l + 1) * kek(l, r);
  if (l >= lens * b) {
    cout << mem;
    return 0;
  }
  ans += (b * lens - l) / (r - l + 1) * kek(l, r);
  long long ost = (b * lens - l) % (r - l + 1);
  ans += kek(l, l + ost - 1);
  cout << ans / d;
}
