#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int inf = 1e18;
long long int b, d;
string a, c;
vector<pair<long long int, long long int>> arr(101);
int main(void) {
  cin >> b >> d;
  cin >> a;
  cin >> c;
  for (int i = 0; i < c.size(); i++) {
    long long int k = i, val = 0;
    for (int j = 0; j < a.size(); j++) {
      if (a[j] == c[k]) {
        k++;
        if (k == c.size()) {
          k = 0;
          val++;
        }
      }
    }
    arr[i] = make_pair(val, k);
  }
  long long int ans = 0, curr = 0;
  for (int i = 0; i < b; i++) {
    ans += arr[curr].first;
    curr = arr[curr].second;
  }
  cout << ans / d << endl;
}
