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

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