#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e2 + 5;
const int inf = MAX * 10;
const long long MOD = 1e9 + 7;
double eps = 1e-9;
char a[MAX];
char c[MAX];
int divide[MAX];
int mod[MAX];
void fun(int len1, int len2) {
  int now;
  for (int i = 0; i < len1; i++) {
    now = i;
    for (int j = 0; j < len2; j++) {
      if (c[now % len1] == a[j]) now++;
    }
    divide[i] = now / len1;
    mod[i] = now % len1;
  }
}
int main() {
  int b, d;
  cin >> b >> d;
  int len1, len2;
  cin >> a;
  cin >> c;
  len1 = strlen(a), len2 = strlen(c);
  fun(len2, len1);
  int now = 0;
  long long ans = 0;
  for (int i = 1; i <= b; i++) {
    ans += divide[now];
    now = mod[now];
  }
  cout << ans / d << endl;
  return 0;
}
