Imports System
 
Module Test
  
  Public Sub Main()
        Dim S = "abcdefg"
        Dim T = "bcg"

        Dim MatchLength As Integer = 0

        For I As Integer = T.Length To 1 Step -1
            For J As Integer = 0 To T.Length - I
                If S.IndexOf(T.Substring(J, I)) <> -1 Then
                    MatchLength = I
                    GoTo ExitLoop
                End If
            Next
        Next

ExitLoop:
        Console.WriteLine(T.Length - MatchLength)
    
  End Sub

End Module