N, M = map(int,input().split())
alist = []
for i in range(M):
    a,b=input().split()
    alist.append([int(a),int(b)])
p = 1
for i in range(M):
    if [alist[i][0],alist[i][1]] == [1,0]:
        p = p*0
for i in range(M-1):
    for j in range(i+1,M):
        if alist[i][0] == alist[j][0] and alist[i][1] != alist[j][1]:
            p = p*0
q = [0 for i in range(N)]
q[0] = 1
for i in range(M):
    q[alist[i][0]-1] = alist[i][1]
for i in range(N):
    q[i] = str(q[i])
if M == 0:
    print(0)
elif M == 1 and alist[0] == [1,0]:
    print(0)
else:
    if p == 0:
        print(-1)
    else:
        print(int(''.join(q)))