N, M = map(int,input().split())
S = []
for i in range(M):
    s = tuple(map(int,input().split()))
    S.append(s)
ans = [-1 for _ in range(N)]

for x in S:
    if ans[x[0]-1] == -1 or ans[x[0]-1] == x[1]:
        ans[x[0]-1] = x[1]
    else:
        print(-1)
        exit()
if N > 1 and ans[0] == 0:
    print(-1)
    exit()
if N == 1 and M == 0:
    print(0)

for i in range(N):
    if ans[i] == -1:    
        if i == 0:
            print('1',end='')
        else:
            print('0',end='')
    else:
        print(ans[i],end='')
print()


