#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
string s1, s2;
int dp[MAXN];
int nex[MAXN];
int main() {
  int b, d;
  cin >> b >> d;
  cin >> s1 >> s2;
  int len1 = s1.size();
  int len2 = s2.size();
  memset(dp, 0, sizeof dp);
  for (int i = 0; i < len2; i++) {
    int now = i;
    for (int j = 0; j < len1; j++) {
      if (s1[j] == s2[now]) {
        now++;
      }
      if (now == len2) {
        dp[i]++;
        now = 0;
      }
    }
    nex[i] = now;
  }
  int ans = 0;
  int now = 0;
  for (int i = 1; i <= b; i++) {
    ans += dp[now];
    now = nex[now];
  }
  cout << ans / d << endl;
}
