#include <bits/stdc++.h>
using namespace std;
int b, d, f[150];
string a, c;
int main() {
  scanf("%d%d", &b, &d);
  cin >> a;
  cin >> c;
  int l1 = a.size();
  int l2 = c.size();
  for (int i = 0; i < l2; i++) {
    int t = 0;
    for (int j = 0; j < l1; j++)
      if (a[j] == c[(i + t) % l2]) t++;
    f[i] = t;
  }
  int ans = 0;
  for (int i = 1; i <= b; i++) ans += f[ans % l2];
  cout << ans / (l2 * d) << endl;
  return 0;
}
