n, m = map(int,input().split())
a = [False]*n
for i in range(m):
    s, c = map(int,input().split())
    if a[s-1]:
        if a[s-1] != c:
            print(-1)
            exit()
    else:
        a[s-1] = c

ans = ''
for t in a:
    if t:
        ans += str(t)
    else:
        ans += '0'
        
if ans[0] == '0':
    print(-1)
    exit()
print(ans)
