n,m=map(int,input().split())
s=[list(map(int,input().split())) for i in range(m)]
def exit():
    import sys
    print(-1)
    sys.exit()
num=['']*n
for i in range(m):
    if num[s[i][0]-1]!='':
        if num[s[i][0]-1]==s[i][1]:
            continue
        else:
            exit()
    else:
        num[s[i][0]-1]=s[i][1]
else:
    if num[0] in [0,'']:
        exit()
    else:
        for i in range(n):
            print(num[i] if num[i]!='' else 0, end='')