#include <bits/stdc++.h>
using namespace std;
using namespace std;
using namespace std;
int dp[1000005 * 10][2];
int a, b;
string s, t;
long long answer;
int current;
int main() {
  cin >> a >> b >> s >> t;
  for (int(i) = 0; (i) < (int((t).size())); ++(i)) {
    int current = i;
    for (int(j) = 0; (j) < (int((s).size())); ++(j))
      if (s[j] == t[current]) {
        ++current;
        if (current == int((t).size())) {
          ++dp[i][0];
          current = 0;
        }
      }
    dp[i][1] = current;
  }
  current = 0;
  for (int(i) = 0; (i) < (a); ++(i)) {
    answer += dp[current][0];
    current = dp[current][1];
  }
  cout << answer / b << endl;
  return 0;
}
