#include <bits/stdc++.h>
using namespace std;
inline void err(istringstream *iss) {}
template <typename T, typename... Args>
void err(istringstream *iss, const T &$val, const Args &...args) {
  string $name;
  *iss >> $name;
  if ($name.back() == ',') $name.pop_back();
  cout << $name << " = " << $val << "; ", err(iss, args...);
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
int n, m, K, T, Q, cn;
int b, d, nxt[105][130], oca[105][105], occ[105][105];
char a[105], c[105];
int dfs(int ai, int ci, int ca, int cc, bool cycled) {
  if (ai == n) return 0;
  if (ca == b) return cc;
  if (!cycled and oca[ai][ci] != -1) {
    int as = ca - oca[ai][ci], cs = cc - occ[ai][ci];
    int nc = (b - 1 - ca) / as;
    return dfs(ai, ci, ca + nc * as, cc + nc * cs, 1);
  } else if (!cycled)
    oca[ai][ci] = ca, occ[ai][ci] = cc;
  int nai, nci, nca, ncc;
  nci = ci + 1;
  if (nci >= m)
    nci -= m;
  else if (nci < 0)
    nci += m;
  ncc = cc + (!nci);
  nai = nxt[ai + 1][c[nci] - 'a'], nca = ca;
  if (nai == n or ai == n - 1) nca++, nai = nxt[n][c[nci] - 'a'];
  return dfs(nai, nci, nca, ncc, cycled);
}
int main() {
  cin.tie(NULL);
  scanf("%d%d%s%s", &b, &d, a, c);
  n = int(strlen(a)), m = int(strlen(c));
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < 26; j++) {
      nxt[i][j] = i == n - 1 ? n : nxt[i + 1][j];
      if (!i) nxt[n][j] = nxt[i][j];
    }
    nxt[i][a[i] - 'a'] = i;
    if (!i) nxt[n][a[i] - 'a'] = i;
  }
  memset(oca, -1, sizeof(oca));
  printf("%d\n", dfs(nxt[0][c[0] - 'a'], 0, 0, 0, 0) / d);
  return 0;
}
