Imports System
Imports System.Linq

Class Program
    Shared Sub Main(args As String())
        Dim input As String() = Console.ReadLine().Split(" ")
        Dim n As Long = CLng(input(0))
        Dim m As Long = CLng(input(1))
        Dim k As Long = CLng(input(2))
        Dim ai = Console.ReadLine().Split(" ")
        Dim bi = Console.ReadLine().Split(" ")
        Dim cntA As Long
        Dim cntB As Long

        Do While True
            If n = cntA Then
                If m = cntB Then
                    Exit Do
                ElseIf CLng(bi(cntB)) <= k Then
                    k -= CLng(bi(cntB))
                    cntB += 1
                Else
                    Exit Do
                End If
            ElseIf m = cntB Then
                If CLng(ai(cntA)) <= k Then
                    k -= CLng(ai(cntA))
                    cntA += 1
                Else
                    Exit Do
                End If
            Else
                If CLng(ai(cntA)) = CLng(bi(cntB)) Then
                    Dim cnt As Long
                    Dim take As Short = 1

                    Do While True
                        cnt += 1
                        If cntA + cnt = n Then
                            take = 2
                            Exit Do

                        ElseIf cntB + cnt = m Then
                            take = 1
                            Exit Do

                        ElseIf CLng(ai(cntA + cnt)) = CLng(bi(cntB + cnt)) Then

                        ElseIf CLng(ai(cntA + cnt)) < CLng(bi(cntB + cnt)) Then
                            take = 1
                            Exit Do
                        Else
                            take = 2
                            Exit Do

                        End If
                    Loop

                    If take = 1 Then
                        If CLng(ai(cntA)) <= k Then
                            k -= CLng(ai(cntA))
                            cntA += 1
                        Else
                            Exit Do
                        End If
                    Else
                        If CLng(bi(cntB)) <= k Then
                            k -= CLng(bi(cntB))
                            cntB += 1
                        Else
                            Exit Do
                        End If
                    End If
                ElseIf CLng(ai(cntA)) < CLng(bi(cntB)) Then
                    If CLng(ai(cntA)) <= k Then
                        k -= CLng(ai(cntA))
                        cntA += 1
                    Else
                        Exit Do
                    End If
                Else
                    If CLng(bi(cntB)) <= k Then
                        k -= CLng(bi(cntB))
                        cntB += 1
                    Else
                        Exit Do
                    End If
                End If
            End If
        Loop

        Console.WriteLine(cntA + cntB)
    End Sub
End Class