#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 3;
int n, m, x, y, nxt[N];
string s, t;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> x >> y;
  cin >> s >> t;
  n = s.size(), m = t.size();
  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++)
      if (t[(nxt[i] + i) % m] == s[j]) nxt[i]++;
  int cnt = 0;
  while (x--) cnt += nxt[cnt % m];
  cout << cnt / m / y << endl;
}
