n,m = map(int,input().split())
sc_lst = [list(map(int,input().split())) for _ in range(m)]

flag1 = False
for i in range(m):
    s1 = sc_lst[i][0]
    c1 = sc_lst[i][1]

    for j in range(i+1,m):
        s2 = sc_lst[j][0]
        c2 = sc_lst[j][1]

        if s1==s2 and c1!=c2:
            answer = -1
            flag1 = True
            break

    if flag1:
        break

if n!=1 and [1, 0] in sc_lst:
    answer = -1
    flag1 = True

if flag1:
    print(answer)

else:
    lst = [0]*n
    for i in range(m):
        s = sc_lst[i][0]
        c = sc_lst[i][1]

        lst[s-1] = c

    answer = ''
    for i in range(n):
        number = lst[i]
        if number!=0:
            answer += str(number)
        else:
            if len(answer)!=0:
                answer += str(number)

    if len(answer)==0:
        answer = 0

    print(answer)