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

ans= 0
flag2=-1
flag3=-1
for i in range(10**(N-1),1000):
    flag=1
    str_i = str(i)
    for j in range(M):
        if len(str_i) <test[j][0]:
            flag3 = 1
            continue
        else:
            if str_i[test[j][0]-1] != str(test[j][1]):
                flag =0
                break
            else:
                continue
    ans = i
    if flag == 1:
        flag2 =ans
        break
if flag3==1:
    print(-1)
else:
    print(flag2)