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

ans = [0] * N
for _ in range(M):
    s, c = map(int, input().split())
    
    if ans[s-1] == 0 or ans[s-1] >= c:
        ans[s-1] = c
    else:
        print("-1")
        break
else:
    ans = ''.join(map(str, ans))
    if ans.startswith('0'):
        print("-1")
    else:
        print(''.join(ans))