#include <bits/stdc++.h>
using namespace std;
int k[111], np[111];
int main() {
  int b, d;
  string a, c;
  cin >> b >> d;
  cin >> a >> c;
  int p;
  for (int i = 0; i < c.size(); ++i) {
    k[i] = 0;
    p = i;
    for (int j = 0; j < a.size(); ++j)
      if (a[j] == c[p]) {
        ++p;
        if (p == c.size()) {
          k[i]++;
          p = 0;
        }
      }
    np[i] = p;
  }
  int ks = 0;
  p = 0;
  for (int i = 0; i < b; ++i) {
    ks += k[p];
    p = np[p];
  }
  ks /= d;
  cout << ks << "\n";
  return 0;
}
