Getting a string from prefixes of other strings

A string S, (1<=|S|<=105) is given and other N (1<=N<=104) strings ti are given (1 <= |ti| <= 50). You have N pens (pi) such that ith pen can write any prefix of ith string. In one operation, we can chose any pen and write any prefix of the corresponding string and keep it back. What is the minimum number of operations required to write S.
Time Limit : 4 seconds
Mem : 256MB