#include <bits/stdc++.h>
using namespace std;
int m, n;
string a, b;
int step[111];
int main() {
  cin >> m >> n >> a >> b;
  for (int i = 0, _n = (int)(((int)(b).size())); i < _n; ++i) {
    bool bad = 1;
    for (int j = 0, _n = (int)(((int)(a).size())); j < _n; ++j)
      if (b[i] == a[j]) bad = 0;
    if (bad) {
      cout << 0 << endl;
      return 0;
    }
  }
  for (int i = 0, _n = (int)(((int)(b).size())); i < _n; ++i) {
    int s = 0;
    for (int j = 0, _n = (int)(((int)(a).size())); j < _n; ++j)
      if (a[j] == b[(i + s) % ((int)(b).size())]) ++s;
    step[i] = s;
  }
  int s = 0;
  for (int i = 0, _n = (int)(m); i < _n; ++i) s += step[s % ((int)(b).size())];
  cout << s / ((int)(b).size()) / n << endl;
  return 0;
}
