#include <bits/stdc++.h>
using namespace std;
char a[200];
char b[200];
int p, q;
pair<int, int> memo[200];
int main() {
  scanf("%d %d", &p, &q);
  scanf("%s", a);
  scanf("%s", b);
  int tam1 = strlen(a);
  int tam2 = strlen(b);
  for (int i = 0; i < (tam2); i++) {
    int k = i;
    memo[i] = make_pair(0, i);
    for (int j = 0; j < (tam1); j++) {
      if (a[j] == b[k]) {
        k++;
        if (k == tam2) {
          memo[i].first++;
          k = 0;
        }
        memo[i].second = k;
      }
    }
  }
  long long int res = 0;
  int k = 0;
  for (int i = 0; i < (p); i++) {
    res = res + memo[k].first;
    k = memo[k].second;
  }
  cout << res / q << endl;
  return 0;
}
