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

a = [list(map(int, input().split())) for _ in range(m)]

ans = [0 for _ in range(n)]
check = [False for _ in range(n)]

flag = 0

for i, j in a:
    if check[i-1] == 0 or ans[i-1] == j:
        ans[i-1] = j
        check[i-1] = True
    else:
        flag = 1
       
if check[0] == False ans m != 0:
    ans[0] = 1

c = ""
for k in ans:
    c+=str(k)

if flag == 1 or len(str(int(c))) != n:
    print(-1)
else:
    print(c)