N,M = (int(x) for x in input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
sc.sort()
broke = False
if N == 1:
    temp1 = 0
    temp2 = False
    if M == 0:
        print(0)
    else:
        for i in range(M):
            if temp2 == False:
                temp1 = sc[i][1]
                temp2 = True
            else:
                if sc[i][1] != temp1:
                    print(-1)
                    broke = True
                    break
        if broke == False:
            print(temp1)
elif N == 2:
    temp1 = [1,0]
    temp2 = [False,False]
    if M == 0:
        print(0)
    else:
        for i in range(M):
            if sc[i][0] == 1:
                if temp2[0] == False:
                    temp1[0] = sc[i][1]
                    temp2[0] = True
                else:
                    if sc[i][1] != temp1[0]:
                        print(-1)
                        broke = True
                        break
            else:
                if temp2[1] == False:
                    temp1[1] = sc[i][1]
                    temp2[1] = True
                else:
                    if sc[i][1] != temp1[1]:
                        print(-1)
                        broke = True
                        break
        if broke == False:
            if temp1[0] == 0:
                print(-1)
            else:
                map1 = map(str,temp1)
                print("".join(map1))
else:
    temp1 = [1,0,0]
    temp2 = [False,False,False]
    if M == 0:
        print(0)
    else:
        for i in range(M):
            if sc[i][0] == 1:
                if temp2[0] == False:
                    temp1[0] = sc[i][1]
                    temp2[0] = True
                else:
                    if sc[i][1] != temp1[0]:
                        print(-1)
                        broke = True
                        break
            elif sc[i][0] == 2:
                if temp2[1] == False:
                    temp1[1] = sc[i][1]
                    temp2[1] = True
                else:
                    if sc[i][1] != temp1[1]:
                        print(-1)
                        broke = True
                        break
            else:
                if temp2[2] == False:
                    temp1[2] = sc[i][1]
                    temp2[2] = True
                else:
                    if sc[i][1] != temp1[2]:
                        print(-1)
                        broke = True
                        break
        if broke == False:
            if temp1[0] == 0:
                print(-1)
            else:
                map1 = map(str,temp1)
                print("".join(map1))