#include <bits/stdc++.h>
using namespace std;
int a[110];
int b[110];
int main() {
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  ios::sync_with_stdio(0);
  long long n, m;
  cin >> n >> m;
  char s1[110], s2[110];
  cin >> s1;
  cin >> s2;
  int len1 = strlen(s1), len2 = strlen(s2);
  int i, j, k;
  for (i = 0; i < len2; i++) {
    int x = i;
    for (j = 0; j < len1; j++) {
      if (s2[x] == s1[j]) {
        x++;
        if (x == len2) {
          x = 0;
          a[i]++;
        }
      }
    }
    b[i] = x;
  }
  long long ans = 0, x = 0;
  for (i = 0; i < n; i++) {
    ans += a[x];
    x = b[x];
  }
  cout << ans / m << endl;
  return 0;
}
