#include <bits/stdc++.h>
using namespace std;
int dp[111];
int beg[111];
int nstr[111], nidx[111], done[111], midx[111], mstr[111];
int main() {
  int b, d, curr, ss;
  string a, c;
  cin >> b >> d >> a >> c;
  int n = a.size(), m = c.size();
  auto first = [](int i, int lim, int& cnt) -> int {
    cnt = i + 1 == lim ? cnt + 1 : cnt;
    return i + 1 < lim ? i + 1 : 0;
  };
  auto g = [](int i, int lim, int& cnt) -> int {
    cnt = i - 1 == -1 ? cnt - 1 : cnt;
    return i == 0 ? lim - 1 : i - 1;
  };
  bool flag;
  for (int i = 0; i < n; ++i) {
    curr = i;
    for (int j = 0; j < m; ++j) {
      flag = 0;
      ss = curr;
      while (a[curr] != c[j]) {
        curr = first(curr, n, nstr[i]);
        if (curr == ss) {
          flag = 1;
          break;
        }
      }
      if (flag) break;
      curr = first(curr, n, nstr[i]);
    }
    if (flag)
      nidx[i] = -1;
    else
      nidx[i] = g(curr, n, nstr[i]), dp[i] = 1;
  }
  beg[n - 1] = nstr[n - 1];
  for (int i = n - 2; i >= 0; --i) {
    if (nstr[i] > nstr[i + 1])
      nidx[i] = nidx[i + 1], nstr[i] = nstr[i + 1];
    else if (nstr[i] == nstr[i + 1])
      nidx[i] = min(nidx[i], nidx[i + 1]);
    beg[i] = nstr[i];
    first(nidx[i], n, beg[i]);
  }
  if (nidx[0] == -1) return cout << 0 << endl, 0;
  for (int i = 0; i < n; ++i) midx[i] = nidx[i], mstr[i] = nstr[i];
  for (int i = n - 2; i >= 0; --i) {
    if (beg[i]) continue;
    int go = first(nidx[i], n, curr);
    beg[i] = beg[go];
    dp[i] += dp[go];
    nidx[i] = nidx[go];
    nstr[i] += nstr[go];
  }
  curr = 0;
  int cnt = 0, res = 0;
  while (1) {
    if (cnt + mstr[curr] >= b) break;
    if (cnt + nstr[curr] < b) {
      cnt += nstr[curr];
      res += dp[curr];
      curr = nidx[curr];
    } else {
      cnt += mstr[curr];
      res++;
      curr = midx[curr];
    }
    curr = first(curr, n, cnt);
  }
  res /= d;
  cout << res << endl;
}
