#include <bits/stdc++.h>
using namespace std;
int N, M;
char S[1000], T[1000];
pair<int, int> R[1000];
int main() {
  scanf("%d%d%s%s", &N, &M, S, T);
  int SL = strlen(S), TL = strlen(T);
  for (int i = 0; i < (TL); ++i) {
    pair<int, int> cur(0, i);
    for (int j = 0; j < (SL); ++j) {
      if (S[j] == T[cur.second]) {
        ++cur.second;
        if (cur.second == TL) {
          ++cur.first;
          cur.second = 0;
        }
      }
    }
    R[i] = cur;
  }
  int result = 0;
  int cur = 0;
  for (int i = 0; i < (N); ++i) {
    result += R[cur].first;
    cur = R[cur].second;
  }
  printf("%d\n", result / M);
}
