n,m = list(map(int, input().split()))
l=[list(map(int, input().split())) for _ in range(m)]
ans=['']*n
for s,c in l:
    i=s-1
    if not ans[i]:
        ans[i]=str(c)
    elif ans[i]!=str(c):
        print(-1)
        exit()

if not ans[0] or ans[0]=='0':
    if n==1:
        print(0)
    else:
        print(-1)
else:
    print(''.join([i if i else '0' for i in ans]))