n,m = map(int,input().split())
L = [-1]*n
li = []
flag = True

for i in range(m):
    a,b = map(int,input().split())
    if n == 1 and a == 1:
        L[0] = b
        break
    elif n == 1 and a != 1:
        flag = False
        break
    else:
        if (a in li) and L[a-1] != b:
            flag = False
            break
        elif a == 1 and b == 0:
            flag = False
            break
        else:
            L[a-1] = b
            li.append(a)
for i in range(n):
    if L[i] == -1:
        L[i] = 0
if flag:
    L = [str(x) for x in L]
    print("".join(L))
else:
    print(-1)