#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, idx, cnt;
  pair<int, int> f[110];
  string a, b;
  scanf("%d %d", &n, &m);
  cin >> a >> b;
  for (int i = 0; i < b.size(); i++) {
    idx = i;
    cnt = 0;
    for (int j = 0; j < a.size(); j++) {
      if (a[j] == b[idx]) idx++;
      if (idx == b.size()) {
        idx = 0;
        cnt++;
      }
    }
    f[i] = make_pair(idx, cnt);
  }
  idx = 0;
  cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt += f[idx].second;
    idx = f[idx].first;
  }
  cout << cnt / m << endl;
  return 0;
}
