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

ans = [0]*N
for _ in range(M):
    a, b = map(int, input().split())
    if ans[a-1] != 0 and ans[a-1] != b:
        ans[a-1] = -1
    elif ans[a-1] == 0:
        ans[a-1] = b
if -1 in ans or sum(ans) == 0:
    print('-1')
else:
    ans = [str(i) for i in ans]
    print(''.join(ans))
    
