#include using namespace std; const int N = 3e5 + 7; const int SIGMA = 26; const char OFFSET = 'a'; int n; string text; int OK[N]; int F[N], l[N]; int V = 0, G[N][SIGMA]; void insert(const string &s){ int v = 0; for(char c: s){ c -= OFFSET; if(G[v][c] == 0) G[v][c] = ++V; v = G[v][c]; } OK[v] = s.size(); } void init(){ queue Q; Q.push(0); while(!Q.empty()){ int v = Q.front(); Q.pop(); for(int c = 0; c < SIGMA; ++c){ int w = G[v][c]; if(w == 0) continue; Q.push(w); if(v == 0) continue; F[w] = F[v]; while(F[w] && G[F[w]][c] == 0) F[w] = F[F[w]]; if(G[F[w]][c]) F[w] = G[F[w]][c]; } for(int c = 0; c < SIGMA; ++c) if(G[v][c] == 0) G[v][c] = G[F[v]][c]; OK[v] = max(OK[v], OK[F[v]]); } } int main(){ cin >> n; cin >> text; for(int i = 0; i < n; ++i){ string cur; cin >> cur; insert(cur); } init(); int cur = 0; for(int i = 0; i < text.size(); ++i){ cur = G[cur][text[i] - OFFSET]; l[i] = OK[cur]; } int last = text.size() - 1, last2 = text.size() - 1, res = 0; for(int i = text.size() - 1; i >= 0; --i){ if(i < last){ if(i < last2){ puts("-1"); exit(0); } last = last2; ++res; } last2 = min(last2, i - l[i]); } if(last == 0){ if(last2 < 0) ++res; else{ puts("-1"); return 0; } } printf("%d\n", res); return 0; }