import sys
N, M = map(int, input().split())
ans = {}
ansstr = []
for _ in range(M):
    S, C = map(int, input().split())
    if S == 1 and C == 0:
        print('-1')
        sys.exit()
    elif S > N:
        print('-1')
        sys.exit()
    elif S in ans:
        if ans[S] != C:
            print('-1')
            sys.exit()
    else:
        ans[S] = C
for i in range(1, N+1):
    if i in ans:
        ansstr.append(ans[i])
    else:
        ansstr.append(0)
if ansstr[0]==0:
    ansstr[0]=1

for i in range(N):
    print(ansstr[i], end="")
