#include <bits/stdc++.h>
using namespace std;
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
void CI(int &_x) { scanf("%d", &_x); }
void CO(int &_x) { cout << _x; }
template <typename T>
void getarray(T a[], int n) {
  for (int i = 0; i < n; i++) cin >> a[i];
}
template <typename T>
void printarray(T a[], int n) {
  for (int i = 0; i < n - 1; i++) cout << a[i] << " ";
  cout << a[n - 1] << endl;
}
const double EPS = 1e-9;
const int INF = 0x7f7f7f7f;
int dr8[8] = {1, -1, 0, 0, 1, -1, -1, 1};
int dc8[8] = {0, 0, -1, 1, 1, 1, -1, -1};
int dr4[4] = {0, 0, 1, -1};
int dc4[4] = {-1, 1, 0, 0};
int kn8r[8] = {1, 2, 2, 1, -1, -2, -2, -1};
int kn8c[8] = {2, 1, -1, -2, -2, -1, 1, 2};
int match[105], nxt[105];
int main() {
  int b, d;
  cin >> b >> d;
  string a, c;
  cin >> a >> c;
  for (int i = 0; i < c.size(); i++) {
    match[i] = 0;
    int temp = i;
    for (int j = 0; j < a.size(); j++)
      if (a[j] == c[temp]) {
        temp++;
        if (temp == c.size()) {
          match[i]++;
          temp = 0;
        }
      }
    nxt[i] = temp;
  }
  int cnt = 0;
  int mm = 0;
  for (int i = 0; i < b; i++) {
    cnt += match[mm];
    mm = nxt[mm];
  }
  cout << cnt / d << "\n";
}
