N, M = [int(a) for a in input().split()]
S = [[int(i) for i in input().split()] for _ in range(M)]
flag = 0
if([1,0] in S):
    flag = 1
    print(-1)
else:
    NUM = 0
    LIST = [-1 for _ in range(M)]
    for s,c in S:
        s -= 1
        if(LIST[s]==-1):
            NUM += c*(10**(N-s-1))
            LIST[s] = c
        else:
            if(LIST[s]!=c):
                flag = 1
                print(-1)
                break
            else:
                continue
    if(LIST[0] == -1):
        if(N>2):
            NUM += 10**(N-1)
        else:
            NUM = 0
    if(flag==0):
        print(NUM)