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

flag = False
l = [0]*n
for i in range(m):
    l[SC[i][0]-1] = SC[i][1]
    if flag == True:
        break
    for j in range(1,m-i):
        if SC[i][0] == SC[j][0]:
            if l[SC[i][0]-1] != l[SC[j][0]-1]:
                print('-1')
                flag = True
                break
    
if flag == False:   
    if (l[0] == 0):
        print('-1')
    else:
        l = l[:n]
        s = ''
        for i in l:
            s += str(i)
        print(int(s))