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=''
for i in num:
    if i == -1:
        s = s + '0'
    else:
        s = s + str(i)
print(s if len(str(int(s))) == N else -1)