n,m = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(m)]
temp = [-1] * n
sc.sort(key=lambda x: x[0])
ans = []
c = 1
print(sc)
for i in sc:
    print(temp,i)
    if temp[i[0]-1] != -1 and temp[i[0]-1] != i[1]:
        print(-1)
        exit()
    temp[i[0]-1] = i[1]
if temp[0] == -1:
    ans = '1'
else:
    ans = str(temp[0])
if ans == '0':
    print(-1)
    exit()
for i in temp[1:]:
    if i == -1:
        ans += '0'
    else:
        ans += str(i)
print(ans)