Thanks, acutally my strings are relatively short, let's say less than 30, but the number of strings can be large (not that large, for the moment, say 10K), so only N is important, not M. It can be safely assumed that the strings don't contain those special characters.