#include <bits/stdc++.h>
using namespace std;
int dp[105][2];
int main() {
  int b, d;
  char a[105], c[105];
  cin >> b >> d >> a >> c;
  int lena = strlen(a);
  int lenc = strlen(c);
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < lenc; i++) {
    int x = i;
    for (int j = 0; j < lena; j++) {
      if (a[j] == c[x]) {
        x++;
        if (x == lenc) {
          dp[i][0]++;
          x = 0;
        }
      }
    }
    dp[i][1] = x;
  }
  int ans = 0, t = 0;
  while (b--) {
    ans += dp[t][0];
    t = dp[t][1];
  }
  cout << ans / d << endl;
}
