Find the longest prefix