#include<iostream>
#include<cstring>
using namespace std;
const int N=1e2+4;
#define int long long
string T;
int n,k;
string s;
int dp[105];
signed main(){
int q,op,x,y;
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>T>>n;
int l=T.size();
for(int i=0;i<=N;i++) dp[i]=1061109567;
dp[0]=0;
for(int i=1;i<=n;i++){
cin>>k;
while(k--){
cin>>s;
int p=s.size();
for(int j=l;j>=0;j--){
if(T.substr(j,p)==s&&j+p<=l){
dp[j+p]=min(dp[j+p],dp[j]+1);
}
}
}
}
cout<<(dp[l]==1061109567?-1:dp[l])<<'\n';
return 0;
}