#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, c;
  int b, d;
  cin >> b >> d;
  cin >> a >> c;
  int i, j;
  int pos[100];
  int cnt[100] = {0};
  for (i = 0; i < c.size(); i++) {
    int now = i;
    for (j = 0; j < a.size(); j++) {
      if (a[j] == c[now]) {
        now++;
        if (now == c.size()) {
          now = 0;
          cnt[i]++;
        }
      }
    }
    pos[i] = now;
  }
  int ans = 0;
  int p = 0;
  for (i = 0; i < b; i++) {
    ans += cnt[p];
    p = pos[p];
  }
  ans /= d;
  cout << ans << endl;
  return 0;
}
