n,m = map(int, input().split())
listA = []
for _ in range(m):
    listA.append(input().split())
flg = False


for i in range(0,10**n):
    if len(str(i)) == n:
        for j in range(m):
            if str(i)[int(listA[j][0])-1] == listA[j][1]:
                flg = True
            else:
                flg = False
                break
        if flg:
            print(i)
            break

            
if not flg:
    print(-1)