#include <bits/stdc++.h>
using namespace std;
int b, d;
string a, c;
pair<int, int> shift[101];
void fillShifts() {
  for (int i = 0; i < c.size(); i++) {
    int j = 0, k = i;
    int cnt = 0;
    while (j < a.size()) {
      if (a[j] == c[k]) {
        k++;
        if (k == c.size()) {
          k = 0;
          cnt++;
        }
      }
      j++;
    }
    shift[i] = pair<int, int>(cnt, k);
  }
}
int getVal() {
  int val = 0, curr = 0;
  for (int i = 0; i < b; i++) {
    val += shift[curr].first;
    curr = shift[curr].second;
  }
  return val / d;
}
int main(int argc, char** argv) {
  cin >> b >> d >> a >> c;
  fillShifts();
  cout << getVal() << endl;
  return 0;
}
