n, m = map(int,input().split())

num = [0]*n

for i in range(m):
    s, c = map(int,input().split())
    if (num[s-1] == c) or (num[s-1] == 0):
        num[s-1] = c
    else:
        print(-1)
        exit()
if num[0] == 0 and n!=1:
    print(-1)
    exit()
else:
    print("".join(map(str,num)))