#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
const int N = 1e4 + 15;
int n, m, b, d, dp[N], ans;
string a, c;
int main() {
  cin >> b >> d >> a >> c;
  n = a.size(), m = c.size();
  for (int i = 0; i < m; ++i)
    for (int j = 0; j < n; ++j) dp[i] += (a[j] == c[(dp[i] + i) % m]);
  for (int i = 0; i < b; ++i) ans += dp[ans % m];
  cout << ans / (m * d) << '\n';
  return 0;
}
