n = []
j = True

N, M = list(map(int, input().split()))
for i in range(N):
    n.append('W')

for i in range(M):
    s, c = list(map(int, input().split()))
    if n[s-1] == "W":
        n[s-1] = c
    elif n[s-1] == c:
        pass
    else:
        print(-1)
        j = False
        
if j == True:
    for i in range(3):
        if n[i] =="W":
            n[i] = 0
    if n[0] == 0:
        print(-1)
    else:
        print(''.join(map(str,n)))