N,M = map(int,input().split())
num = [0] * N
l = []
for i in range(M):
    l.append(list(map(int,input().split())))
l = list(map(list, set(map(tuple, l))))
count = [0] * N

for i in range(len(l)):
    a = l[i][0]
    b = l[i][1]
    num[a-1] = b
    count[a-1] += 1

flag = True
for c in count:
    if c > 1:
        flag = False
if len(num) > 1 and num[0] == 0:
    flag = False
if flag == False:
    print(-1)
else:
    num = [str(i) for i in num]
    print(''.join(num))