N, M = map(int, input().split())
lis_Number = [[] for i in range(N)]
for m in range(M):
    s, c = map(int, input().split())
    lis_Number[s-1].append(c)

lis_ans = [[] for i in range(N)]
condition_ok = True
for i in range(N):
    if len(list(set(lis_Number[i]))) == 0:
        lis_ans[i] = 0
    elif len(list(set(lis_Number[i]))) == 1:
        if (i == 0) &(lis_Number[i][0]==0):
            condition_ok = False
        else :
            lis_ans[i] = lis_Number[i][0]
    else :
        condition_ok = False

if condition_ok:
    haha = ''
    for i in range(N):
        haha += str(lis_ans[i])
    ans = int(haha)
else :
    ans = -1

print(ans)