N, M = [int(i) for i in input().split(' ')]
SC = []
for _ in range(M):
    SC.append([int(i) for i in input().split(' ')])

ch = [-1] * N

for s,c in SC:
    if ch[s-1] == -1 or ch[s-1] == c:
        ch[s-1] = c
    else:
        print(-1)
        exit()

if ch[0] == 0:
    print(-1)
    exit()
else:
    ans = 0
    for i,num in enumerate(ch):
        if i == 0:
            if num == -1:
                ans += 10 ** (N-1)
            else:
                ans += num * 10 ** (N-1)
        else:
            if num == -1:
                ans += 0
            else:
                ans += num * 10 ** (N-i-1)
print(ans)