What is the minimum numbers of characters which are to be deleted from a string S such that another string Pattern is no longer its substring?

Let there be a string S which may or may not have another string Pattern as its substring (one or many instances)…
We need to find the minimum number of deletions to be performed on this string S such that pattern is no longer a substring of S…
I tried using dynamic with keeping a state as in KMP but could not formalize it…