Length of the Longest Valid Substring