#include <bits/stdc++.h>
using namespace std;
int la, lb;
char A[110];
char B[110];
int n, m;
int IDX[110];
int dp[110];
void preCal() {
  for (int j = 0; j < lb; j++) {
    int sum = 0;
    int k = j;
    for (int i = 0; i < la; i++) {
      if (A[i] == B[k]) {
        k++;
        if (k == lb) {
          sum++;
          k = 0;
        }
      }
    }
    dp[j] = sum;
    IDX[j] = k;
  }
}
int cal() {
  preCal();
  int a = 0;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans = ans + dp[a];
    a = IDX[a];
  }
  return ans / m;
}
int main() {
  scanf("%d%d", &n, &m);
  scanf("%s", &A);
  scanf("%s", &B);
  la = strlen(A);
  lb = strlen(B);
  printf("%d\n", cal());
  return 0;
}
