n,m = map(int,input().split())
x = []
for i in range(m):
    x.append(list(map(int,input().split())))
ans = [0]*n
flag = [10]*n
a = 0
for i in range(m):
    if flag[x[i][0]-1] == 10 or flag[x[i][0]-1] == x[i][1]:
        ans[x[i][0]-1] = x[i][1]
        flag[x[i][0]-1] = x[i][1]
    else :
        a = 1
        break
answer = 0
if a == 0:
    for i in range(n):
        answer += ans[i]*10**(n-i-1)
else :
    answer = -1
if n != 1 and [1, 0] in x:
    print(-1)
else :
    print(answer)