CF427D Match & Catch

Description

Police headquarter is monitoring signal on different frequency levels. They have got two suspiciously encoded strings $ s_{1} $ and $ s_{2} $ from two different frequencies as signals. They are suspecting that these two strings are from two different criminals and they are planning to do some evil task. Now they are trying to find a common substring of minimum length between these two strings. The substring must occur only once in the first string, and also it must occur only once in the second string. Given two strings $ s_{1} $ and $ s_{2} $ consist of lowercase Latin letters, find the smallest (by length) common substring $ p $ of both $ s_{1} $ and $ s_{2} $ , where $ p $ is a unique substring in $ s_{1} $ and also in $ s_{2} $ . See notes for formal definition of substring and uniqueness.

Input Format

The first line of input contains $ s_{1} $ and the second line contains $ s_{2} $ $ (1

Output Format

Print the length of the smallest common unique substring of $ s_{1} $ and $ s_{2} $ . If there are no common unique substrings of $ s_{1} $ and $ s_{2} $ print -1.

Explanation/Hint

Imagine we have string $ a=a_{1}a_{2}a_{3}...a_{|a|} $ , where $ |a| $ is the length of string $ a $ , and $ a_{i} $ is the $ i^{th} $ letter of the string. We will call string $ a_{l}a_{l+1}a_{l+2}...a_{r} $ $ (1