N,M=map(int,input().split())
num=[-1]*N
for i in range(M):
    s,c=map(int,input().split())
    if num[s-1] == -1:
        num[s-1] = c
    elif num[s-1] != c:
        print(-1)
        exit()

s=''
if num[0] == -1:
    print(-1)
else:
    for i in num:
        if i == -1:
            s = s + '0'
        else:
            s = s + str(i)
    print(s if s != '000' else -1)