#include <bits/stdc++.h>
std::string a;
std::string c;
int b, d;
int const maxn = 108;
int matched[maxn];
int pos[maxn];
int main() {
  std::ios::sync_with_stdio(false);
  std::cin >> b >> d;
  std::cin >> a >> c;
  int la = a.size();
  int lc = c.size();
  for (int i = 0; i < lc; i++) {
    int k = i, count = 0;
    for (int j = 0; j < la; j++)
      if (a[j] == c[k]) {
        k++;
        if (k == lc) count++, k = 0;
      }
    matched[i] = count;
    pos[i] = k;
  }
  int ans = 0;
  for (int i = 0, j = 0; i < b; i++, j = pos[j]) ans += matched[j];
  std::cout << ans / d << '\n';
}
