n,m = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]
if n == 1:
    for x in range(10):
        xs = str(x)
        for i in range(m):
            if xs[sc[i][0]-1] != sc[i][1]:
                break
        else:
            print(x)
            break
    else:
        print(-1)
elif n == 2:
    for x in range(10,100):
        xs = str(x)
        for i in range(m):
            if xs[sc[i][0]-1] != sc[i][1]:
                break
        else:
            print(x)
            break
    else:
        print(-1)
else:
    for x in range(100,1000):
        xs = str(x)
        for i in range(m):
            if int(xs[sc[i][0]-1]) != sc[i][1]:
                break
        else:
            print(x)
            break
    else:
        print(-1)