#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9, maxn = 1e5 + 223, N = 1e6 + 20, LOG = 21, mod = 1e9 + 7;
const int dx[] = {0, 0, -1, 1}, dy[] = {1, -1, 0, 0};
const long double eps = 1e-12, pi = 3.14159265359;
const pair<unsigned long long, unsigned long long> base = make_pair(1171, 3307);
const long long INF = 1e18;
int b, d, to[maxn], cnt[maxn];
string a, c;
int main() {
  cin >> b >> d >> a >> c;
  int n = a.size(), m = c.size();
  for (int i = 0; i < m; ++i) {
    int cur = i, v = 0;
    for (int j = 0; j < n; ++j) {
      if (a[j] != c[cur]) continue;
      cur++;
      v += cur / m;
      cur %= m;
    }
    cnt[i] = v;
    to[i] = cur;
  }
  int cur = 0, res = 0;
  while (b--) {
    res += cnt[cur];
    cur = to[cur];
  }
  res /= d;
  cout << res << '\n';
  return 0;
}
