N, M = map(int, input().split())
num = [list(map(int, input().split())) for _ in range(M)]
ans = [-1] *N
call = True
for k in range(M):
    if ans[num[k][0] -1] == -1 or ans[num[k][0] -1] == num[k][1]:
        ans[num[k][0] -1] = num[k][1]
    else:
        call = False
        break

if call == True:
    if N != 1:
        ans = [0 if a == -1 else a for a in ans]
        if ans[0] == 0:
            ans[0] = 1
        print(''.join(map(str,ans)))
    else:
        if ans[0] == -1:
            print(0)
        else:
            print(''.join(map(str,ans)))
else:
    print(-1)