#include <bits/stdc++.h>
using namespace std;
int pt[105];
int num[105];
int main() {
  int b, d;
  string a, c;
  while (cin >> b >> d) {
    cin >> a >> c;
    memset(pt, -1, sizeof(pt));
    memset(num, 0, sizeof(num));
    for (int i = 0; i < c.length(); i++) {
      int c_idx = i;
      for (int j = 0; j < a.length(); j++) {
        if (a[j] == c[c_idx]) c_idx++;
        if (c_idx == c.length()) {
          num[i]++;
          c_idx = 0;
        }
      }
      pt[i] = c_idx;
    }
    int idx = 0;
    int res = 0;
    for (int i = 0; i < b; i++) {
      res += num[idx];
      idx = pt[idx];
    }
    cout << res / d << '\n';
  }
  return 0;
}
