#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 100;
int b, d, lenA, lenC;
string a, c;
int dp[maxn + 10], nex[maxn + 10];
void cope(int x) {
  dp[x] = 0;
  nex[x] = x;
  int use = 0;
  while (use < lenA) {
    if (a[use] == c[nex[x]]) {
      if (++nex[x] == lenC) {
        dp[x]++;
        nex[x] = 0;
      }
    }
    use++;
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  while (cin >> b >> d) {
    cin >> a >> c;
    lenA = a.length(), lenC = c.length();
    for (int(i) = 0; (i) < (lenC); (i)++) cope(i);
    int x = 0, num = 0;
    for (int(i) = 0; (i) < (b); (i)++) {
      num += dp[x];
      x = nex[x];
    }
    num /= d;
    cout << num << endl;
  }
  return 0;
}
