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

ans = ['*'] * N

if M != 0:

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