#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, c;
  int b, d;
  cin >> b >> d;
  cin >> a >> c;
  long long ans = 0;
  long long cnt = 0;
  long long cnt1;
  int cnt2[101], pos[101], cnt3[101];
  long long l = a.length();
  long long r = c.length();
  bool fl = true;
  if (r == 1) {
    char c1 = c[0];
    int cnt4 = 0;
    for (int i = 0; i < l; i++) {
      if (a[i] == c1) cnt4++;
    }
    cout << b * cnt4 / d << endl;
    return 0;
  }
  string w;
  w = a;
  for (int i = 0; i < 1000; i++) {
    w = w + a;
  }
  long long ll = w.length();
  long long j = 0;
  long long x, y;
  bool flag = true;
  for (int i = 0; i < 101; i++) {
    pos[i] = 0;
  }
  int i, cnt4, cnt5;
  for (i = 0; (i < ll) && (flag); i++) {
    if (w[i] == c[j]) {
      j++;
      if (j == r) {
        j = 0;
        cnt++;
        y = i;
      }
      if ((j == 1)) {
        if (pos[i % l] == 1) {
          flag = false;
          cnt4 = cnt2[i % l];
          cnt5 = cnt3[i % l];
          cnt = cnt - cnt2[i % l];
          cnt1 = i / l - cnt3[i % l];
          if ((y % l) > (i % l)) fl = false;
        } else {
          pos[i % l] = 1;
          cnt2[i % l] = cnt;
          cnt3[i % l] = i / l;
        }
      }
    }
  }
  if (cnt == 0) {
    cout << '0' << endl;
    return 0;
  }
  bool fl2 = false;
  if (b > cnt5) {
    b -= cnt5;
    ans += cnt4;
    ans += (b / cnt1) * cnt;
    b = b % cnt1;
    if ((b == 0)) {
      if (fl) fl2 = true;
    }
  } else {
    fl = false;
  }
  w = "";
  if (fl == false)
    w = a;
  else {
    for (i = (y % l) + 1; i < l; i++) w.push_back(a[i]);
  }
  for (int i = 0; i < b - 1; i++) {
    w = w + a;
  }
  ll = w.length();
  j = 0;
  for (i = 0; i < ll; i++) {
    if (w[i] == c[j]) {
      j++;
      if (j == r) {
        j = 0;
        ans++;
      }
    }
  }
  j = 0;
  int ans6 = 0;
  for (i = 0; i < l; i++) {
    if (a[i] == c[j]) {
      j++;
      if (j == r) {
        j = 0;
        ans6++;
      }
    }
  }
  if (fl2) ans -= ans6 + 1;
  if (a == c) ans--;
  ans /= d;
  cout << ans << endl;
  return 0;
}
