import sys
N,M = map(int,input().split())
ans = [0]*N
dict1 = {}
for x in range(M):
    a,b = map(int,input().split())
    if((a in dict1) != True):
        dict1[a] = b
    elif(dict1[a] == b):
        dict1[a] = b
    else:
        print(-1)
        sys.exit()
for k, v in dict1.items():
    ans[k-1] = v
print(ans)
l = "".join([str(n) for n in ans])
int_l = int(l)
print(int_l)
len_l = len(str(int_l))
if(N >= 2 and ( 0 in dict1)):
    print(-1)
else:
    print(int_l)