N,M=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(M)]

for x in range(0, 1000):
    nx=x//10
    d=[x%10]
    while(nx):
        d.append(nx%10)
        nx//=10
    d.reverse

    if len(d)!=N: continue

    chk=True
    for i in range(M):
        if(d[arr[i][0]-1]!=arr[i][1]): chk=False
    if chk: print(x);exit()

print(-1)