Module Module1

    Sub Main()
        Dim ketasu As Integer
        Dim jokensu As Integer

        Dim tempstr(1) As String
        tempstr = Console.ReadLine().Split(" "c)

        ketasu = CInt(tempstr(0))
        jokensu = CInt(tempstr(1))

        Dim joken(jokensu - 1, 1) As Integer

        For i As Integer = 0 To jokensu - 1
            Dim tempjoken(1) As String
            tempjoken = Console.ReadLine().Split(" "c)
            joken(i, 0) = CInt(tempjoken(0))
            joken(i, 1) = CInt(tempjoken(1))
        Next

        Dim sonzaiflg As Boolean = True
        Dim ansval(ketasu - 1) As Integer
        '初期化
        For a As Integer = 0 To ketasu - 1
            ansval(a) = -1
        Next



        For t As Integer = 0 To jokensu - 1
            '桁数1以外は左からヒトケタ目が0以外の指定はダメ
            If ketasu <> 1 AndAlso (joken(t, 0) = 1 AndAlso joken(t, 1) = 0) Then
                sonzaiflg = False
                Exit For
            End If
            '既に指定した桁にに値を入れようとしたらアウト
            If ansval(joken(t, 0) - 1) <> -1 AndAlso ansval(joken(t, 0) - 1) <> joken(t, 1) Then
                sonzaiflg = False
            End If

            'ここで初めて値をセット
            ansval(joken(t, 0) - 1) = joken(t, 1)
        Next
        '存在しない時はここで終わり
        If Not sonzaiflg Then
            Console.WriteLine("-1")
            Console.ReadKey()
            Exit Sub
        End If


        Dim printans As String = ""
        For k As Integer = 0 To ansval.Length - 1
            If ansval.Length = 1 AndAlso ansval(0) = -1I Then
                printans = "0"
                Exit For
            ElseIf ansval.Length <> 1 AndAlso ansval(0) = -1I Then
                printans = "1"
                Continue For
            End If

            If ansval(k) = -1I Then
                printans = printans & "0"
            Else
                printans = printans & ansval(k).ToString
            End If

        Next


        Console.WriteLine(printans)









    End Sub




End Module
