#include <bits/stdc++.h>
using namespace std;
const int MAXL = 101;
string a, c;
int f[MAXL];
int main() {
  int b, d;
  cin >> b >> d;
  cin >> a >> c;
  int n = a.length(), m = c.length();
  for (int i = 0; i < m; i++) {
    f[i] = 0;
    for (int j = 0; j < n; j++) {
      if (a[j] == c[(f[i] + i) % m]) f[i]++;
    }
  }
  int cp = 0;
  for (int i = 0; i < b; i++) {
    cp += f[cp % m];
  }
  cout << cp / m / d << endl;
  return 0;
}
