N,M = map(int,input().split())

num = [-1 for _ in range(N)]

flag = False
for i in range(M):
    s,c = map(int,input().split())
    if num[s-1] == -1 or num[s-1] == c:
        num[s-1] = c
    else:
        break
else:
    flag = True

if flag==False or (num[0]==0 and N>1):
    print(-1)
else:
    ans = 0
    if num[0] == -1:
        num[0] = 1
    for i in range(N):
        if num[i]!=-1:
            ans += num[i]*(10**(N-i-1))
    print(ans)
 