#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 1e9;
const int sz = 20;
void input() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int x, y;
  cin >> x >> y;
  string s1, s2;
  cin >> s1 >> s2;
  int l1 = (int)s1.size(), l2 = (int)s2.size();
  vector<int> chr(l2, 0);
  for (int i = 0; i < l2; ++i) {
    for (int j = 0; j < l1; ++j) {
      if (s2[(i + chr[i]) % l2] == s1[j]) ++chr[i];
    }
  }
  int ans = 0;
  for (int i = 0; i < x; ++i) ans += chr[ans % l2];
  cout << (ans / l2 / y) << "\n";
}
int main() {
  input();
  return 0;
}
