rank,n = map(int,input().split())
num = [-1,-1,-1]
cond = True
for i in range(n):
    s,c = map(int,input().split())
    if num[s-1] == -1 or num[s-1] == c:
        num[s-1] = c
    else:
        print(-1)
        cond = False
        break

if num[rank-1] == 0:
    print(-1)
    cond = False

if cond == True:
    for i in range(3):
        if num[i] == -1:
            num[i] = 0
    if rank == 3:
        if num[0] == 0:
            print(-1)
        else:
            print(num[0]*100+num[1]*10+num[2])
    else:
        if rank == 2:
            if num[1] == 0:
                print(-1)
            else:
                print(num[1]*10+num[2])
        else:
            print(num[2])
