#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e2 + 9;
pair<int, int> dp[MAX][MAX], pr, dp2[MAX];
int a, b, x;
string s, t;
int main() {
  cin >> a >> b >> s >> t;
  for (int i = 0; i < s.size(); i++)
    for (int j = 0; j < t.size(); j++) {
      int p = j, k = i;
      for (; p < t.size() && k < s.size(); k++)
        if (s[k] == t[p]) p++;
      dp[i][j] = {k, p};
    }
  for (int j = 0; j < t.size(); j++) {
    pr = {0, j}, x = 0;
    while (1) {
      pr = {dp[pr.first][pr.second].first, dp[pr.first][pr.second].second};
      if (pr.second == t.size()) x++, pr.second = 0;
      if (pr.first == s.size()) {
        dp2[j] = {x, pr.second};
        break;
      }
    }
  }
  x = 0;
  pr = {0, 0};
  for (int i = 0; i < a; i++) x += dp2[pr.second].first, pr = dp2[pr.second];
  cout << x / b;
}
