#ABC157 Guess the number
n,m = map(int,input().split())
sc = [input().split() for _ in range(m)]
ans =[]
if len(sc) == 0:
    print('0')
    exit()

if n == 1:
    d = []
    if m == 1:
        print(sc[0][1])
        exit()
    else:
        for i in range(m):
            d.append(sc[m][1])
        if set(d) == 1:
            print(d[0])
        else:
            print('-1')
            exit()
    
for i in range(10**(n-1),10**n):
    cnt = 0
    seq = str(i)
    for j in range(m):
        if seq[int(sc[j][0])-1] == sc[j][1]:
            cnt += 1
    if cnt == m:
        ans.append(i)
        
if len(ans) == 0:
    print('-1')
else:
    print(min(ans))