#include <bits/stdc++.h>
using namespace std;
int n, m;
int f[1000], g[1000];
char a[1000], b[1000];
int main() {
  cin >> n >> m;
  scanf("%s", a);
  scanf("%s", b);
  int alen = strlen(a);
  int blen = strlen(b);
  for (int i = 0; i < blen; i++) {
    int cur = i;
    int cnt = 0;
    for (int j = 0; j < alen; j++) {
      if (a[j] == b[cur]) {
        cur++;
        if (cur == blen) cur = 0, cnt++;
      }
    }
    f[i] = cur;
    g[i] = cnt;
  }
  int ans = 0, cur = 0;
  for (int i = 0; i < n; i++) {
    ans += g[cur];
    cur = f[cur];
  }
  cout << ans / m << endl;
  return 0;
}
