#include <bits/stdc++.h>
using namespace std;
const long long N = 3e2 + 100;
string a, b;
long long c, d, n, m;
bool mark[N];
pair<long long, long long> dp[N], dp2[N];
pair<long long, long long> h[N];
pair<long long, long long> nex(pair<long long, long long> k) {
  long long x = k.first;
  k.first = dp[x].first;
  k.second += dp[x].second;
  return k;
}
pair<long long, long long> nex2(pair<long long, long long> k) {
  long long x = k.first;
  k.first = dp2[x].first;
  k.second += dp2[x].second;
  return k;
}
void cler(long long x) {
  for (long long i = 0; i < n; i++) {
    h[i] = make_pair(-1LL, -1LL);
  }
  h[x] = make_pair(0LL, 0LL);
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> c >> d;
  cin >> a >> b;
  n = a.size();
  m = b.size();
  for (long long i = 0; i < n; i++) {
    mark[a[i]] = true;
  }
  for (long long i = 0; i < m; i++) {
    if (!mark[b[i]]) return cout << "0\n", 0;
  }
  for (long long i = 0; i < n; i++) {
    long long ind = 0;
    dp[i].first = i;
    while (ind < m) {
      if (a[dp[i].first] == b[ind]) ind++;
      dp[i].first++;
      if (dp[i].first == n) dp[i].first = 0, dp[i].second++;
    }
  }
  for (long long i = 0; i < n; i++) {
    cler(i);
    dp2[i].first = i;
    for (long long j = 0, x; j < d; j++) {
      x = dp2[i].first;
      dp2[i] = nex(dp2[i]);
      if (h[dp[x].first] != make_pair(-1LL, -1LL)) {
        long long t = d - j - 1;
        long long len = h[x].first + 1 - h[dp[x].first].first;
        long long tmp = t / len;
        dp2[i].second +=
            tmp * (h[x].second + dp[x].second - h[dp[x].first].second);
        t -= tmp * len;
        for (long long l = 0, x; l < t; l++) {
          dp2[i] = nex(dp2[i]);
        }
        break;
      }
      h[dp[x].first] = make_pair(h[x].first + 1, h[x].second + dp[x].second);
    }
  }
  cler(0);
  pair<long long, long long> pos = make_pair(0LL, 0LL);
  long long cnt = -1;
  while (pos.second < c) {
    cnt++;
    long long x = pos.first;
    pos = nex2(pos);
    if (h[pos.first] != make_pair(-1LL, -1LL)) {
      if (pos.second >= c)
        break;
      else
        cnt++;
      long long len = h[x].second + dp2[x].second - h[dp2[x].first].second;
      long long t = c - 1 - pos.second;
      long long tmp = t / len;
      cnt += tmp * (h[x].first + 1 - h[dp2[x].first].first);
      pos.second += tmp * len;
      if (pos.second < c) cnt--;
      while (pos.second < c) {
        cnt++;
        pos = nex2(pos);
      }
      break;
    }
    h[pos.first] = make_pair(h[x].first + 1, h[x].second + dp2[x].second);
  }
  if (pos == make_pair(0LL, c)) cnt++;
  cout << cnt << "\n";
  return 0;
}
