#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, save[102], b3dk[102];
  cin >> n >> m;
  string str, s;
  cin >> str >> s;
  for (int i = 0; i < s.size(); i++) {
    int current = i;
    save[i] = 0;
    for (int j = 0; j < str.size(); j++) {
      if (s[current] == str[j]) {
        current++;
        if (current == s.size()) {
          save[i]++;
          current = 0;
        }
      }
    }
    b3dk[i] = current;
  }
  int fan = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    ans += save[fan];
    fan = b3dk[fan];
  }
  cout << ans / m << endl;
  return 0;
}
