open System

[<EntryPoint>]
let main argv =

    let S = Console.ReadLine().ToCharArray() |> Array.toList
    let T = Console.ReadLine().ToCharArray() |> Array.toList

    let mutable count = 0
    let mutable current = 0
    List.iter (fun x -> if x = T.Item(current) then 
                            count <- count + 1
                        current <- current + 1) S

    printfn "%d" count

    0
