n, m = map(int, input().split())
sc = [map(int, input().split()) for i in range(m)]
s, c = [list(i) for i in zip(*sc)]

ans = [10, 10, 10]
flag = 0
sum = 0

for i in range(m):
    if ans[s[i]-1] != c[i]:
        if ans[s[i]-1] == 10:
            ans[s[i]-1] = c[i]
        else:
            print("-1")
            flag = 1
            break

for i in range(3):
    if ans[i] == 10:
        ans[i] = 0


for i in range(n):
    sum += ans[-(i+1)] * (10 ** i)

if flag == 0:
    if n != 1 and ans[2] == 0:
        print("-1")
    else:
        print(sum)